Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
Yura has (n) homework assignments. For each assignment, its weight (a_i) is known — the number of course points Yura will receive if he completes it. Yura wants to choose a subset of assignments to maximize the total number of points. However, he has one problem: some assignments are too time-consuming. If Yura works on two assignments at positions (i) and (j) ((i \neq j)), there must be enough other assignments between them; otherwise, he will get distracted and fail to complete them. Formally, for any two chosen assignments with indices (i) and (j), the following condition must hold: (|i - j| \gt \max(a_i, a_j)). Find the maximum total weight Yura can obtain by choosing a subset of assignments satisfying this condition. The first line contains a single integer (t) ((1 \le t \le 10^4)) — the number of test cases. The first line of each test case contains a single integer (n) ((1 \le n \le 2 \cdot 10^5)) — the size of the array (a). The second line contains (n) integers (a_1, a_2, \dots, a_n) ((0 \le a_i \le 10^9)) — the elements of the array. It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, output a single integer — the maximum total weight of the selected assignments. In the first example, it is optimal to choose assignments with indices (1) and (5). In the third example, it is optimal to choose assignments with indices (1) and (6). |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
382780207 |
dd_thehung |
G |
July 15, 2026, 11:30 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
93 |
4300800 |
|
|
|
382885761 |
prathamkashyap |
G |
July 16, 2026, 5:07 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
93 |
5836800 |
|
|
|
382720479 |
55555ANH |
G |
July 15, 2026, 1:03 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
93 |
5939200 |
|
|
|
382739498 |
usedchang |
G |
July 15, 2026, 5:02 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
93 |
11980800 |
|
|
|
382776434 |
1984518110qq |
G |
July 15, 2026, 10:59 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
109 |
5734400 |
|
|
|
382735408 |
Vishnu_Kashyap_7 |
G |
July 15, 2026, 4:14 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
109 |
5836800 |
|
|
|
382779708 |
prosinessL |
G |
July 15, 2026, 11:26 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
109 |
6656000 |
|
|
|
382703078 |
Aadyant_2705 |
G |
July 14, 2026, 6:58 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
109 |
6656000 |
|
|
|
382697351 |
IIDRAGONBUSTII |
G |
July 14, 2026, 6:05 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
109 |
6656000 |
|
|
|
382739123 |
akshatbhutra |
G |
July 15, 2026, 4:58 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
24 |
109 |
6758400 |
|
|
|
382724020 |
Jamshen |
G |
July 15, 2026, 2:01 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
78 |
4300800 |
|
|
|
382712208 |
QRQRQR |
G |
July 14, 2026, 9:18 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
78 |
5939200 |
|
|
|
382774380 |
RoOoOoKie |
G |
July 15, 2026, 10:41 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
78 |
6758400 |
|
|
|
382774413 |
wsr999 |
G |
July 15, 2026, 10:41 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
78 |
7270400 |
|
|
|
382806124 |
xjmxjm |
G |
July 15, 2026, 2:40 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
78 |
8294400 |
|
|
|
382736544 |
call_God |
G |
July 15, 2026, 4:29 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
78 |
8294400 |
|
|
|
382726678 |
liang_han |
G |
July 15, 2026, 2:41 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
78 |
9318400 |
|
|
|
382728488 |
Everly_Galahad |
G |
July 15, 2026, 3:05 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
78 |
11468800 |
|
|
|
382738595 |
PhoenixCore |
G |
July 15, 2026, 4:53 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
93 |
2560000 |
|
|
|
382788361 |
UltimateAAJ |
G |
July 15, 2026, 12:38 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
24 |
93 |
4096000 |
|
|
|
382816085 |
shy_robot_No8 |
G |
July 15, 2026, 3:45 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
1740800 |
|
|
|
382736341 |
Mr_Bald |
G |
July 15, 2026, 4:26 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
2355200 |
|
|
|
382790881 |
hyper1423 |
G |
July 15, 2026, 12:53 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
4096000 |
|
|
|
382790625 |
liyuff |
G |
July 15, 2026, 12:51 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
4300800 |
|
|
|
382822364 |
Chef_Ramzi |
G |
July 15, 2026, 4:32 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
4403200 |
|
|
|
382738899 |
Nathan.Li |
G |
July 15, 2026, 4:55 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
4403200 |
|
|
|
382774473 |
link1k |
G |
July 15, 2026, 10:42 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
5222400 |
|
|
|
382742597 |
bsn666 |
G |
July 15, 2026, 5:34 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
6348800 |
|
|
|
382778208 |
tctony |
G |
July 15, 2026, 11:13 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
7577600 |
|
|
|
382741324 |
yuyc |
G |
July 15, 2026, 5:21 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
24 |
78 |
7680000 |
|
|
|
382842799 |
Ati_3 |
G |
July 15, 2026, 7:12 p.m. |
OK |
Java 21 |
TESTS |
24 |
343 |
7065600 |
|
|
|
382695107 |
codewithedeepak |
G |
July 14, 2026, 5:44 p.m. |
OK |
Java 21 |
TESTS |
24 |
343 |
35942400 |
|
|
|
382833869 |
hinny |
G |
July 15, 2026, 5:56 p.m. |
OK |
Java 21 |
TESTS |
24 |
390 |
39526400 |
|
|
|
382817979 |
tiwari_selling_kulfi |
G |
July 15, 2026, 4 p.m. |
OK |
Java 21 |
TESTS |
24 |
453 |
35635200 |
|
|
|
382817968 |
vineetiwari |
G |
July 15, 2026, 4 p.m. |
OK |
Java 21 |
TESTS |
24 |
484 |
35635200 |
|
|
|
382869589 |
NpHardcore_05 |
G |
July 16, 2026, 2:03 a.m. |
OK |
Java 21 |
TESTS |
24 |
562 |
63692800 |
|
|
|
382741547 |
ishurajora_23 |
G |
July 15, 2026, 5:24 a.m. |
OK |
Java 21 |
TESTS |
24 |
609 |
38400000 |
|
|
|
382829337 |
ashmittt |
G |
July 15, 2026, 5:22 p.m. |
OK |
Java 21 |
TESTS |
24 |
1437 |
177664000 |
|
|
|
382809830 |
ayushvem8795 |
G |
July 15, 2026, 3:03 p.m. |
OK |
Kotlin 2.2 |
TESTS |
24 |
140 |
0 |
|
|
|
382810650 |
chinesedfan |
G |
July 15, 2026, 3:09 p.m. |
OK |
Node.js |
TESTS |
24 |
375 |
91238400 |
|
|
|
382727042 |
fatalerror |
G |
July 15, 2026, 2:46 a.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
265 |
28774400 |
|
|
|
382790136 |
dev_roast99 |
G |
July 15, 2026, 12:48 p.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
265 |
30617600 |
|
|
|
382729447 |
kamio-misuzu |
G |
July 15, 2026, 3:14 a.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
281 |
31846400 |
|
|
|
382707674 |
akane646 |
G |
July 14, 2026, 7:54 p.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
296 |
35430400 |
|
|
|
382703432 |
egortomat |
G |
July 14, 2026, 7:02 p.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
312 |
43622400 |
|
|
|
382741179 |
golomb |
G |
July 15, 2026, 5:20 a.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
328 |
34201600 |
|
|
|
382736035 |
user_not_found_404___ |
G |
July 15, 2026, 4:23 a.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
515 |
32051200 |
|
|
|
382858643 |
AldyPy |
G |
July 15, 2026, 11:08 p.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
546 |
39731200 |
|
|
|
382714410 |
Little_Sheep_Yawn |
G |
July 14, 2026, 10:22 p.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
562 |
40652800 |
|
|
|
382724480 |
DairXP |
G |
July 15, 2026, 2:09 a.m. |
OK |
PyPy 3-64 |
TESTS |
24 |
1562 |
120729600 |
|
|
|
382694816 |
JesusLlaven |
G |
July 14, 2026, 5:42 p.m. |
OK |
Python 2 |
TESTS |
24 |
843 |
18124800 |
|
|
|
382886246 |
Newbalance1 |
G |
July 16, 2026, 5:13 a.m. |
OK |
Python 3 |
TESTS |
24 |
828 |
44032000 |
|
|
|
382690956 |
shriyapachunuri |
G |
July 14, 2026, 5:14 p.m. |
OK |
Python 3 |
TESTS |
24 |
875 |
48128000 |
|
|
|
382837491 |
aryansahare |
G |
July 15, 2026, 6:23 p.m. |
OK |
Python 3 |
TESTS |
24 |
953 |
54374400 |
|
|
|
382691935 |
EmeraldBeast |
G |
July 14, 2026, 5:20 p.m. |
OK |
Python 3 |
TESTS |
24 |
1968 |
49459200 |
|
|
|
382822073 |
one_autum_leaf |
G |
July 15, 2026, 4:30 p.m. |
OK |
Rust 2024 |
TESTS |
24 |
78 |
12595200 |
|
|
|
382834021 |
typedef_struct |
G |
July 15, 2026, 5:57 p.m. |
OK |
Rust 2024 |
TESTS |
24 |
93 |
13414400 |
|
|
|
382709056 |
camc |
G |
July 14, 2026, 8:12 p.m. |
OK |
Rust 2024 |
TESTS |
24 |
93 |
16588800 |
|
|
remove filters
Back to search problems