Codeforces Round 1096 (Div. 3)

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.

ContestId
Name
Phase
Frozen
Duration (Seconds)
Relative Time
Start Time
2227 Codeforces Round 1096 (Div. 3) FINISHED False 9000 2820287 April 30, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 7884 ) E It All Went Sideways PROGRAMMING binary search data structures dp greedy

Yousef has (n) columns of cubes standing side by side. The (i)-th column contains (a_i) identical unit cubes stacked vertically. Initially gravity pulls cubes downwards, so every column (i) contains exactly (a_i) cubes at heights (1, 2, \dots, a_i). Suddenly, gravity shifts to the right. Each cube slides horizontally as far to the right as possible. A cube cannot pass through or overlap other cubes, and it must remain at its original height. The final configuration is uniquely determined by the initial heights. Before the gravity shift, Yousef may perform at most one operation: choose an index (i) and decrease (a_i) by (1) (i.e. remove one cube from that column). He may also choose to do nothing. A cube is said to move if its column index after the gravity shift is different from its original column index. Find the maximum possible number of cubes that will move after the gravity shift, assuming Yousef applies the single decrease optimally (or chooses not to apply it). The first line contains an integer (t) ((1 \le t \le 10^4)) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer (n) ((1 \le n \le 2 \cdot 10^5)) — the length of the array. The second line of each test case contains (n) integers (a_1, a_2, \dots, a_n) ((1 \le a_i \le n)) — 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 possible number of cubes that will move after the gravity shift, assuming Yousef applies the single decrease optimally (or chooses not to apply it). In the first test case, it is optimal to perform the operation on index (5), making the array (a = 1, 2, 3, 2, 0). After the gravity shift, every remaining cube will move. The answer is (1+2+3+2 = 8). It can be proven that a greater answer does n

Tutorials

Codeforces Round 1096 (Div. 3) — Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
373152480 volhalink E April 30, 2026, 4:37 p.m. OK C# 13 TESTS 8 125 23961600
373170568 Aritra2005 E April 30, 2026, 6:47 p.m. OK C++17 (GCC 7-32) TESTS 8 46 0
373159654 Linuyin E April 30, 2026, 5:01 p.m. OK C++17 (GCC 7-32) TESTS 8 46 0
373160415 qwerty_zero E April 30, 2026, 5:03 p.m. OK C++17 (GCC 7-32) TESTS 8 46 102400
373156576 khongbietdatgi E April 30, 2026, 4:51 p.m. OK C++17 (GCC 7-32) TESTS 8 46 3276800
373186652 marlonberland E May 1, 2026, 1:29 a.m. OK C++17 (GCC 7-32) TESTS 8 62 0
373185711 Satvik_Raj E May 1, 2026, 12:52 a.m. OK C++17 (GCC 7-32) TESTS 8 62 0
373185647 drjones E May 1, 2026, 12:50 a.m. OK C++17 (GCC 7-32) TESTS 8 62 0
373183549 Ab3dy E April 30, 2026, 11:10 p.m. OK C++17 (GCC 7-32) TESTS 8 62 0
373183520 pylons E April 30, 2026, 11:08 p.m. OK C++17 (GCC 7-32) TESTS 8 62 0
373183066 anand_nr E April 30, 2026, 10:49 p.m. OK C++17 (GCC 7-32) TESTS 8 62 0

remove filters

Back to search problems