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
Pizano built an array (a) of (n) towers, each consisting of (a_i \ge 0) blocks. Pizano can knock down a tower so that the next (a_i) towers grow by (1). In other words, he can take the element (a_i), increase the next (a_i) elements by one, and then set (a_i) to (0). The blocks that fall outside the array of towers disappear. If Pizano knocks down a tower with (0) blocks, nothing happens. Pizano wants to knock down all (n) towers in any order, each exactly once . That is, for each (i) from (1) to (n), he will knock down the tower at position (i) exactly once. Moreover, the resulting array of tower heights must be non-decreasing . This means that after he knocks down all (n) towers, for any (i < j), the tower at position (i) must not be taller than the tower at position (j). You are required to output the maximum (\text{MEX}) of the resulting array of tower heights. The (\text{MEX}) of an array is the smallest non-negative integer that is not present in the array. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains an integer (n) ((1 \leq n \leq 10^5)) — the number of towers. The second line of each test case contains (n) integers — the initial heights of the towers (a_1, \ldots, a_n) ((0 \leq a_i \leq 10^9)). It is guaranteed that the sum of (n) over all test cases does not exceed (10^5). For each test case, output a single integer — the maximum (\text{MEX}) of the final array. Explanation for the first test case. Explanation for the second test case. Note that all towers were knocked down exactly once, and the final array of heights is non-decreasing. |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
318039244 |
tin.le2 |
F |
May 1, 2025, 8:23 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
14 |
62 |
102400 |
|
|
|
318040747 |
nikolashami |
F |
May 1, 2025, 8:46 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
14 |
62 |
2457600 |
|
|
|
318053506 |
Teddydudu |
F |
May 2, 2025, 2:09 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
14 |
108 |
102400 |
|
|
|
318010894 |
HeartBlueArchive |
F |
May 1, 2025, 4:26 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
14 |
108 |
2457600 |
|
|
|
318049609 |
brianxi |
F |
May 2, 2025, 12:26 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
14 |
186 |
1638400 |
|
|
|
318058220 |
MintCat |
F |
May 2, 2025, 3:34 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
61 |
102400 |
|
|
|
318041164 |
Tahirliyev |
F |
May 1, 2025, 8:53 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
62 |
102400 |
|
|
|
318039287 |
dmraykhan |
F |
May 1, 2025, 8:24 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
62 |
102400 |
|
|
|
318037314 |
OG_Matveychick1 |
F |
May 1, 2025, 7:55 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
62 |
1638400 |
|
|
|
318026477 |
Ekber_Ekber |
F |
May 1, 2025, 5:59 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
62 |
1638400 |
|
|
|
318037600 |
Noche_6 |
F |
May 1, 2025, 7:59 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
77 |
102400 |
|
|
|
318018974 |
Rubikun |
F |
May 1, 2025, 5:09 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
77 |
102400 |
|
|
|
318018963 |
kaiboy |
F |
May 1, 2025, 5:09 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
77 |
819200 |
|
|
|
318063211 |
blackrabbit-zmk |
F |
May 2, 2025, 4:59 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
77 |
1638400 |
|
|
|
318012287 |
propane |
F |
May 1, 2025, 4:29 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
14 |
93 |
0 |
|
|
|
318053056 |
cooluo |
F |
May 2, 2025, 1:58 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
46 |
2969600 |
|
|
|
318039959 |
.ELPoP. |
F |
May 1, 2025, 8:34 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
62 |
0 |
|
|
|
318018751 |
Urtusea |
F |
May 1, 2025, 5:08 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
62 |
0 |
|
|
|
318027240 |
glebtyapkov |
F |
May 1, 2025, 6:05 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
62 |
819200 |
|
|
|
318057898 |
9756 |
F |
May 2, 2025, 3:28 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
62 |
32153600 |
|
|
|
318029118 |
Mangooste |
F |
May 1, 2025, 6:22 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
77 |
0 |
|
|
|
318055248 |
countless |
F |
May 2, 2025, 2:43 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
77 |
102400 |
|
|
|
318038929 |
crystal_castles |
F |
May 1, 2025, 8:19 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
77 |
102400 |
|
|
|
318035607 |
Boboge |
F |
May 1, 2025, 7:33 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
77 |
102400 |
|
|
|
318020778 |
MeIoN_is_UMP45 |
F |
May 1, 2025, 5:19 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
14 |
77 |
102400 |
|
|
remove filters
Back to search problems