Special thanks to Michael276382, itslucaslam, ansonlee2025.yay, cl_lmc, KTMC_Jack_Hui, jonahgamer110, sqrteipi, kevinxiehk for testing!
In addition, congratulations to SaiBadrik012, elliotchl, and i_love_mickey_0331 for solving all problems in this contest!
Author: jonahgamer110
Output $$$2 \times (L \times W + W \times H + L \times H)$$$.
import sys
def solve():
input = sys.stdin.read
data = input().split()
if not data:
return
l = int(data[0])
w = int(data[1])
h = int(data[2])
print(2 * (l * w + w * h + l * h))
if __name__ == "__main__":
solve()
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int l, w, h;
if (!(cin >> l >> w >> h)) return 0;
cout << 2 * (l * w + w * h + l * h) << "\n";
return 0;
}
Adapted from: 2026 WYIOI P2
Loop through the array to compute the sum, the maximum and minimum element of $$$[S_1, S_2, \dots , S_N]$$$. Output the sum minus the maximum and minimum.
Note that there are built-in functions for these operations. Refer to the code sections below.
import sys
def solve():
input = sys.stdin.read
data = input().split()
if not data:
return
n = int(data[0])
s = [int(x) for x in data[1 : n + 1]]
print(sum(s) - min(s) - max(s))
if __name__ == "__main__":
solve()
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
if (!(cin >> n)) return 0;
vector<int> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
int sum = accumulate(s.begin(), s.end(), 0);
int min_s = *min_element(s.begin(), s.end());
int max_s = *max_element(s.begin(), s.end());
cout << sum - min_s - max_s << "\n";
return 0;
}
Author: cl_lmc
A constructive approach is to place the sequence elements by alternating steps starting from the center:
- $$$A_1 = \lfloor \frac{N}{2} \rfloor + 1$$$.
- $$$A_2 = A_1 + 1$$$
- $$$A_3 = A_2 - 2$$$
- $$$A_4 = A_3 + 3$$$
- $$$\dots$$$
By alternating directions between adding and subtracting the step index $$$i$$$, the values trace out all distinct integers from $$$1$$$ to $$$N$$$ without ever falling out of bounds or repeating. This guarantees a valid sequence for any $$$N \ge 3$$$.
import sys
def solve():
input = sys.stdin.read
n = int(input().strip())
ans = [0] * n
ans[0] = n // 2 + 1
sign = 1
for i in range(1, n):
ans[i] = ans[i - 1] + sign * i
sign = -sign
print(*ans)
if __name__ == "__main__":
solve()
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
if (!(cin >> n)) return 0;
vector<int> a(n);
a[0] = n / 2 + 1;
int sign = 1;
for (int i = 1; i < n; i++) {
a[i] = a[i - 1] + sign * i;
sign = -sign;
}
for (int i = 0; i < n; ++i) cout << a[i] << (i == n - 1 ? "" : " ");
cout << "\n";
return 0;
}
Author: jiangordon
First, convert the current time into total minutes elapsed from midnight:
Since a day has $$$1440$$$ minutes ($$$24 \times 60$$$), we can find the time on the clock after any number of days by taking the modulo:
Finally, extract the new hour and minute from the time:
- $$$H' = \lfloor \frac{\text{final_minutes}}{60} \rfloor$$$
- $$$M' = \text{final_minutes} \pmod{60}$$$
import sys
def solve():
input = sys.stdin.read
data = input().split()
if not data:
return
h = int(data[0])
m = int(data[1])
k = int(data[2])
total_minutes = h * 60 + m + k
final_minutes = total_minutes % 1440
new_h = final_minutes // 60
new_m = final_minutes % 60
print(new_h, new_m)
if __name__ == "__main__":
solve()
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long h, m, k;
if (!(cin >> h >> m >> k)) return 0;
long long total_minutes = h * 60 + m + k;
long long final_minutes = total_minutes % 1440;
long long new_h = final_minutes / 60;
long long new_m = final_minutes % 60;
cout << new_h << " " << new_m << "\n";
return 0;
}
Adapted from: 2022A - Bus to Pénjamo
To maximize the number of happy people, we want to pair up as many family members together as possible. Since each table holds at most 2 people:
- For even-sized families, every member can be paired up with another member of the same family. Thus, all members of even families will be happy.
- For an odd-sized family of size $$$A_i$$$, we can pair up $$$A_i - 1$$$ members, leaving 1 member unpaired. Ideally, we want to seat this person alone in a row to make them happy. However, if there are no remaining tables to seat them alone, we’ll have to seat them with someone from another family. This means the other person might no longer be happy since they are no longer seated alone.
- If the number of remaining tables is greater than or equal to the number of unpaired people, all unpaired people can sit alone and remain happy. Otherwise, some people will have to share a tables, and their happiness will be affected. In that case, the number of happy people will be $$$2 \times \text{remaining_tables} - \text{remaining_people}$$$.
import sys
def solve():
input = sys.stdin.read
data = input().split()
if not data:
return
n = int(data[0])
k = int(data[1])
a = [int(x) for x in data[2 : n+2]]
happy = 0
leftalone = 0
for x in a:
happy += (x // 2) * 2
k -= x // 2
leftalone += x % 2
if leftalone > k:
happy += k * 2 - leftalone
else:
happy += leftalone
print(happy)
if __name__ == "__main__":
solve()
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
long long k;
if (!(cin >> n >> k)) return 0;
long long happy = 0;
long long leftalone = 0;
for (int i = 0; i < n; ++i) {
long long a;
cin >> a;
happy += (a / 2) * 2;
k -= a / 2;
leftalone += a % 2;
}
if (leftalone > k) {
happy += k * 2 - leftalone;
} else {
happy += leftalone;
}
cout << happy << "\n";
return 0;
}
Author: jiangordon
This problem asks us to count how many streetlights illuminate each query point $$$(R_j, C_j)$$$, where each streetlight $$$i$$$ illuminates a square region from $$$(X_i - B_i, Y_i - B_i)$$$ to $$$(X_i + B_i, Y_i + B_i)$$$.
A query point $$$(R, C)$$$ is illuminated by streetlight $$$i$$$ if and only if:
which can be rewritten as:
Given the constraints where $$$K, Q \le 5000$$$, we can iterate through each of the $$$Q$$$ queries and check all $$$K$$$ streetlights using a simple loop.
import sys
def solve():
input = sys.stdin.read
data = input().split()
if not data:
return
n = int(data[0]);
m = int(data[1]);
k = int(data[2]);
idx = 3
lights = []
for _ in range(k):
x, y, b = map(int, input_data[index : index + 3])
lights.append((x, y, b))
idx += 3
q = int(data[idx]);
idx += 1
ans = []
for _ in range(q):
r = int(data[idx]);
c = int(data[idx + 1]);
idx += 2
count = 0
for x, y, b in lights:
if abs(x - r) <= b and abs(y - c) <= b:
count += 1
ans.append(str(count))
print("\n".join(ans) + "\n")
if __name__ == "__main__":
solve()
#include <bits/stdc++.h>
using namespace std;
struct light {
long long x, y, b;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long n, m, k;
if (!(cin >> n >> m >> k)) return 0;
vector<light> lights(k);
for (int i = 0; i < k; i++) cin >> lights[i].x >> lights[i].y >> lights[i].b;
int q;
if (!(cin >> q)) return 0;
while (q--) {
long long r, c;
cin >> r >> c;
int count = 0;
for (auto [x, y, b] : lights) if (abs(x - r) <= b && abs(y - c) <= b) count++;
cout << count << "\n";
}
return 0;
}
Author: jiangordon
From the statement, the total force $$$B_i$$$ on planet $$$i$$$ is given as:
We can separate this sum into two parts: the sum of the masses of all other planets, and the sum of the distance offsets:
Let $$$S = \sum_{j=1}^{N} A_j$$$ be the sum of all planet masses. Then $$$\sum_{j \neq i} A_j = S - A_i$$$.
Let $$$D_i = \sum_{j \neq i} \vert{}j - i\vert{}$$$ represent the total distance penalty from all other planets to planet $$$i$$$. We can precompute $$$D_i$$$ in $$$O(N)$$$ using the positions to the left and right of $$$i$$$:
Substituting these back into the equation:
Notice that $$$S$$$ is a constant total sum across all planets. If we sum the equation $$$A_i + B_i + D_i = S$$$ for all $$$i$$$ from $$$1$$$ to $$$N$$$:
Since $$$\sum_{i=1}^{N} A_i = S$$$, this simplifies to:
Alternatively, by looking at any individual pair of equations or summing all $$$B_i + D_i$$$, we can deduce the total mass sum $$$S$$$. In fact, summing $$$B_i + D_i$$$ for all planets gives $$$(N-1)S$$$, allowing us to find:
Once we find $$$S$$$, each individual planet's mass can be directly recovered:
import sys
def solve():
input = sys.stdin.read
data = input().split()
if not data:
return
n = int(data[0])
b = [0] + [int(x) for x in data[1 : n+1]]
d = [0] * (n + 1)
for i in range(1, n + 1):
d[i] = i * (i - 1) // 2 + (n - i) * (n - i + 1) // 2
total_sum = 0
for i in range(1, n + 1):
total_sum += b[i] + d[i]
s = total_sum // (n - 1)
a = [0] * (n + 1)
for i in range(1, n + 1):
a[i] = s - b[i] - d[i]
print(*(a[1:]))
if __name__ == "__main__":
solve()
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
if (!(cin >> n)) return 0;
vector<long long> b(n + 1);
for (int i = 1; i <= n; i++) cin >> b[i];
vector<long long> d(n + 1);
for (int i = 1; i <= n; i++) d[i] = i * (i - 1) / 2 + (n - i) * (n - i + 1) / 2;
long long s = 0LL;
for (int i = 1; i <= n; i++) s += b[i] + d[i];
s /= n - 1;
vector<long long> a(n + 1);
for (int i = 1; i <= n; i++) a[i] = s - b[i] - d[i];
for (int i = 1; i <= n; i++) cout << a[i] << (i == n ? "" : " ");
cout << '\n';
return 0;
}




