Codeforces Round 1037 (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
2126 Codeforces Round 1037 (Div. 3) FINISHED False 8100 23642723 July 17, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 1148 ) G2 Big Wins! (hard version) PROGRAMMING binary search data structures divide and conquer two pointers

This is the hard version of the problem. The difference between the versions is that in this version (a_i \leq n). You are given an array of (n) integers (a_1, a_2, \dots, a_n). Your task is to find a subarray (al, r) (a continuous sequence of elements (a_l, a_{l + 1}, \dots, a_r)) for which the value of the expression (\text{med}(al, r) - \min(al, r)) is maximized. Here: (\text{med}) is the median of the subarray, that is, the element at position (\left\lceil \frac{k + 1}{2} \right\rceil) after sorting the subarray, where (k) is its length; (\min) is the minimum element of this subarray. For example, consider the array (a=1, 4, 1, 5, 3, 3) and choose the subarray (a2, 5 = 4, 1, 5, 3). In sorted form, it looks like (1, 3, 4, 5). (\text{med}(a2, 5) = 4), since (\left\lceil \frac{4 + 1}{2} \right\rceil =) the third element in the sorted subarray is (4); (\min(a2, 5) = 1), since the minimum element is (1). In this example, the value (\text{med} - \min = 4 - 1 = 3). The first line contains an integer (t) ((1 \le t \le 10^4)) — the number of test cases. The first line of each test case contains one integer (n) ((1 \leq n \leq 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 \leq a_i \leq n)) — the elements of the array. It is guaranteed that the sum of (n) across all test cases does not exceed (2 \cdot 10^5). For each test case, output one integer — the maximum possible value of (\text{med} - \min) among all subarrays of the array. In the first example, consider the array: (a=3,\ 2,\ 5,\ 3,\ 1) you can choose the subarray (a2,\ 3), that is, the elements (2,\ 5). The length of the subarray is (2). The median is the element at position (\left\lceil \dfrac{3}{2} \right\rceil = 2) in the sorted subarray. After sorting, we get $$$[2,

Tutorials

144845

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
329526293 -firefly- G2 July 17, 2025, 5:14 p.m. OK C# 13 TESTS 20 187 6451200
329579657 ywjylx G2 July 18, 2025, 5:03 a.m. OK C++17 (GCC 7-32) TESTS 20 187 11264000
329572326 marscheng G2 July 18, 2025, 3:33 a.m. OK C++17 (GCC 7-32) TESTS 20 406 30208000
329582839 zhoujingchen G2 July 18, 2025, 5:38 a.m. OK C++17 (GCC 7-32) TESTS 30 468 26316800
329535305 souvenir_vayne G2 July 17, 2025, 6:19 p.m. OK C++17 (GCC 7-32) TESTS 20 625 26009600
329535195 souvenir_vayne G2 July 17, 2025, 6:17 p.m. OK C++17 (GCC 7-32) TESTS 20 687 26009600
329574151 dipanshisharma906 G2 July 18, 2025, 3:55 a.m. OK C++17 (GCC 7-32) TESTS 20 703 26112000
329582708 zhoujingchen G2 July 18, 2025, 5:37 a.m. OK C++17 (GCC 7-32) TESTS 30 703 26419200
329576080 SF-Manman G2 July 18, 2025, 4:20 a.m. OK C++17 (GCC 7-32) TESTS 20 1421 102400
329557465 gabriel88766 G2 July 18, 2025, 12:30 a.m. OK C++17 (GCC 7-32) TESTS 20 1453 44032000
329557590 gabriel88766 G2 July 18, 2025, 12:34 a.m. OK C++17 (GCC 7-32) TESTS 20 1468 43827200
329576301 yxfql G2 July 18, 2025, 4:23 a.m. OK C++20 (GCC 13-64) TESTS 20 77 1945600
329563122 su_da G2 July 18, 2025, 2:07 a.m. OK C++20 (GCC 13-64) TESTS 20 93 18739200
329566246 Kagarii22 G2 July 18, 2025, 2:37 a.m. OK C++20 (GCC 13-64) TESTS 20 108 7577600
329561533 su_da G2 July 18, 2025, 1:46 a.m. OK C++20 (GCC 13-64) TESTS 20 124 35328000
329539241 Palbudir G2 July 17, 2025, 6:53 p.m. OK C++20 (GCC 13-64) TESTS 20 140 23961600
329544364 ahmetalp G2 July 17, 2025, 7:47 p.m. OK C++20 (GCC 13-64) TESTS 20 171 2764800
329573255 Caylex G2 July 18, 2025, 3:44 a.m. OK C++20 (GCC 13-64) TESTS 20 202 18534400
329546875 bhavya_19 G2 July 17, 2025, 8:19 p.m. OK C++20 (GCC 13-64) TESTS 20 265 31846400
329530782 HusseinFarhat G2 July 17, 2025, 5:43 p.m. OK C++20 (GCC 13-64) TESTS 20 296 102400
329545827 Kyte G2 July 17, 2025, 8:05 p.m. OK C++20 (GCC 13-64) TESTS 20 390 32665600
329564987 su_da G2 July 18, 2025, 2:26 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 62 3481600
329571345 Aword G2 July 18, 2025, 3:23 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 2048000
329562573 fishcathu G2 July 18, 2025, 2:01 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 4096000
329541462 postpone G2 July 17, 2025, 7:16 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 2048000
329573364 A.I.skeleton_ G2 July 18, 2025, 3:45 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 4608000
329563289 su_da G2 July 18, 2025, 2:09 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 18636800
329563578 su_da G2 July 18, 2025, 2:12 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 18739200
329563187 su_da G2 July 18, 2025, 2:08 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 18739200
329531898 Firefly_2025target_GM G2 July 17, 2025, 5:51 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 92 1228800
329564451 UFEQ G2 July 18, 2025, 2:21 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 93 102400
329542472 BOT_DURGESH1 G2 July 17, 2025, 7:26 p.m. OK PyPy 3-64 TESTS 20 780 37580800
329553966 JakeMate14 G2 July 17, 2025, 10:41 p.m. OK Rust 2021 TESTS 20 1155 35635200

remove filters

Back to search problems