Codeforces Round 1061 (Div. 2)

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
2156 Codeforces Round 1061 (Div. 2) FINISHED False 7200 15089123 Oct. 24, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 951 ) E Best Time to Buy and Sell Stock PROGRAMMING binary search data structures games greedy

The beauty of an array (b) of length (m) (with (m \ge 2)) is defined as the largest value of (b_j - b_i) over all pairs of indices (i) and (j) such that (1\le i < j\le m). More formally, it is equal to (\max\limits_{1\le i < j\le m} (b_j - b_i)). Note that the beauty might be negative if the array is strictly decreasing. Hao and Alex play a turn-based game on an array (a) of length (n). Initially, all elements of the array are unlocked. The players take turns alternately, with Hao going first . On Hao's turn, he selects one unlocked element from array (a) and removes it. On Alex's turn, he selects one unlocked element from array (a) and locks it (so it can no longer be removed by Hao). The game continues until all elements of (a) are either locked or removed. It can be proven that the game lasts exactly (n) turns, and exactly (\left\lfloor \frac{n}{2} \right\rfloor) elements will remain locked in array (a) at the end. Hao wants to minimize the beauty of the final array of locked elements, while Alex wants to maximize it. Determine the beauty of the final array if both players play optimally. 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 a single integer (n) ((4\le n\le 10^5)) — the size of the array (a). The second line contains (n) integers (a_1, a_2, \ldots, a_n) ((1 \le a_i \le 10^9)) — the elements of the array (a). 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 representing the beauty of the final array if both Hao and Alex play optimally. In the first test case, the game may proceed as follows. Bolded elements are locked by Alex: Turn 1 (Hao): Remove element (1) (at position (2)), resulting in $$$5, 2, 3, 4

Tutorials

Codeforces Round 1061 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
345689346 Perfound E Oct. 25, 2025, 5:51 a.m. OK C++17 (GCC 7-32) TESTS 35 155 2355200
345678847 wabca E Oct. 25, 2025, 3:49 a.m. OK C++17 (GCC 7-32) TESTS 35 202 12697600
345668612 HongLou_LaMiYa E Oct. 25, 2025, 12:36 a.m. OK C++17 (GCC 7-32) TESTS 35 234 3276800
345673676 137QWQ E Oct. 25, 2025, 2:28 a.m. OK C++17 (GCC 7-32) TESTS 35 280 1638400
345654968 GauravPawarR E Oct. 24, 2025, 8:16 p.m. OK C++17 (GCC 7-32) TESTS 35 281 14745600
345647312 NamanKr E Oct. 24, 2025, 7:09 p.m. OK C++17 (GCC 7-32) TESTS 35 312 4915200
345653005 NotDWT E Oct. 24, 2025, 7:56 p.m. OK C++17 (GCC 7-32) TESTS 35 390 409600
345670277 shai_hulud E Oct. 25, 2025, 1:16 a.m. OK C++17 (GCC 7-32) TESTS 35 452 16793600
345678262 chaitanya_2408 E Oct. 25, 2025, 3:40 a.m. OK C++17 (GCC 7-32) TESTS 35 468 25804800
345644459 SGL513 E Oct. 24, 2025, 6:50 p.m. OK C++17 (GCC 7-32) TESTS 35 483 7782400
345623738 nwblanton E Oct. 24, 2025, 5:31 p.m. OK C++20 (GCC 13-64) TESTS 35 93 204800
345613880 MAXXia E Oct. 24, 2025, 4:27 p.m. OK C++20 (GCC 13-64) TESTS 35 108 12800000
345640260 RaresPoinaru E Oct. 24, 2025, 6:26 p.m. OK C++20 (GCC 13-64) TESTS 35 124 64204800
345672696 lddlinan E Oct. 25, 2025, 2:10 a.m. OK C++20 (GCC 13-64) TESTS 35 140 1740800
345639939 amano_hina E Oct. 24, 2025, 6:25 p.m. OK C++20 (GCC 13-64) TESTS 35 140 14438400
345673420 ngmhhay E Oct. 25, 2025, 2:24 a.m. OK C++20 (GCC 13-64) TESTS 35 171 3174400
345668671 giullia E Oct. 25, 2025, 12:37 a.m. OK C++20 (GCC 13-64) TESTS 35 186 20480000
345676209 sbzsz E Oct. 25, 2025, 3:10 a.m. OK C++20 (GCC 13-64) TESTS 35 187 37273600
345615800 IamHereForFun E Oct. 24, 2025, 4:30 p.m. OK C++20 (GCC 13-64) TESTS 35 202 14438400
345675030 chuanqilaozu E Oct. 25, 2025, 2:51 a.m. OK C++20 (GCC 13-64) TESTS 35 202 24268800
345614466 I_am_Domik E Oct. 24, 2025, 4:28 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 109 10342400
345665670 hungchi17 E Oct. 24, 2025, 11:04 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 109 21196800
345624832 brbrpatapimus E Oct. 24, 2025, 5:36 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 140 11571200
345623301 PaTTern E Oct. 24, 2025, 5:29 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 140 11878400
345623293 1121Jiang E Oct. 24, 2025, 5:29 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 156 12902400
345638198 interlude E Oct. 24, 2025, 6:16 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 171 3276800
345652801 serialcomder E Oct. 24, 2025, 7:54 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 171 11468800
345617383 dizgusted E Oct. 24, 2025, 4:33 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 202 11468800
345662341 SATSKY_2025target_LGM E Oct. 24, 2025, 9:51 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 218 3174400
345665802 denilb E Oct. 24, 2025, 11:07 p.m. OK C++23 (GCC 14-64, msys2) TESTS 35 218 3891200
345662214 shivansh_123 E Oct. 24, 2025, 9:49 p.m. OK Java 21 TESTS 35 3217 38400000
345628658 sikchisagar9330 E Oct. 24, 2025, 5:53 p.m. OK Java 21 TESTS 35 3984 43417600
345662782 marcin7cd E Oct. 24, 2025, 10 p.m. OK PyPy 3 TESTS 35 3624 35532800
345644729 Fyind E Oct. 24, 2025, 6:52 p.m. OK PyPy 3-64 TESTS 35 1952 69939200

remove filters

Back to search problems