Codeforces Round 1049 (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
2140 Codeforces Round 1049 (Div. 2) FINISHED False 7200 18977123 Sept. 9, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 12292 ) C Ultimate Value PROGRAMMING data structures games greedy

Let's define a function (f(a)) for an array (a) of length (n) as ()f(a) = \textrm{cost} + (a_1 - a_2 + a_3 - a_4 \cdots a_n)() where (\textrm{cost}) is zero initially. Now consider the scenario where Alice and Bob are given an array (a) of length (n). They play a game taking at most (10^{100}) turns alternately with Alice going first. In each turn, they must perform any one (only one) of the following operations: End the game for both Alice and Bob. Choose two indices (l,r) with (1 \le l \le r \le n) and swap (a_l) and (a_r); this adds ((r - l)) to the (\textrm{cost}). Assume that Alice tries to maximize (f(a)) and Bob tries to minimize it. Your task is to determine the final value of (f(a)) assuming 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) ((1 \le n \le 2\cdot10^5)) — the length of the array (a). The second line contains (n) integers (a_1,a_2,a_3,\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 (2\cdot10^5). For each testcase, output a single integer — the final value of (f(a)) assuming both players play optimally. For the first testcase, it is optimal for Alice to end the game on her first turn. So the final value of (\textrm{cost} = 0) and (f(a) = 0 + 1000 - 1 = 999). For the fourth testcase, it is optimal for Alice to swap (a_1) and (a_6), and then it is optimal for Bob to end the game on his first turn. So the final value of (\textrm{cost} = 5) and (f(a) = 5 + 15 - 14 + 1 - 14 + 1 - 1=-7).

Tutorials

Codeforces Round 1049 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
337857780 og.kostya C Sept. 9, 2025, 5:55 p.m. OK C# 13 TESTS 13 203 9216000
337895748 cirnovlove C Sept. 10, 2025, 4:13 a.m. OK C++17 (GCC 7-32) TESTS 13 78 0
337847503 Knight78 C Sept. 9, 2025, 4:33 p.m. OK C++17 (GCC 7-32) TESTS 13 78 0
337843777 Vivekpatel1702 C Sept. 9, 2025, 4:26 p.m. OK C++17 (GCC 7-32) TESTS 13 78 102400
337895118 Ciyekua C Sept. 10, 2025, 4:04 a.m. OK C++17 (GCC 7-32) TESTS 13 78 1638400
337904189 paragpatkulkar123 C Sept. 10, 2025, 6:01 a.m. OK C++17 (GCC 7-32) TESTS 13 93 0
337903733 Lucas4732 C Sept. 10, 2025, 5:56 a.m. OK C++17 (GCC 7-32) TESTS 13 93 0
337902818 Rashford_10 C Sept. 10, 2025, 5:46 a.m. OK C++17 (GCC 7-32) TESTS 13 93 0
337899530 _dop_ C Sept. 10, 2025, 5:05 a.m. OK C++17 (GCC 7-32) TESTS 13 93 0
337899357 Sujal01 C Sept. 10, 2025, 5:03 a.m. OK C++17 (GCC 7-32) TESTS 13 93 0
337897253 zxr123375 C Sept. 10, 2025, 4:33 a.m. OK C++17 (GCC 7-32) TESTS 13 93 0
337850255 Kaedemaple C Sept. 9, 2025, 5:03 p.m. OK C++20 (GCC 13-64) TESTS 13 46 5836800
337903091 Re_frain C Sept. 10, 2025, 5:49 a.m. OK C++20 (GCC 13-64) TESTS 13 62 0
337846296 chennie C Sept. 9, 2025, 4:31 p.m. OK C++20 (GCC 13-64) TESTS 13 62 0
337897544 Ankita_13 C Sept. 10, 2025, 4:37 a.m. OK C++20 (GCC 13-64) TESTS 13 62 102400
337885691 jinyq C Sept. 10, 2025, 1:27 a.m. OK C++20 (GCC 13-64) TESTS 13 62 24883200
337903458 Re_frain C Sept. 10, 2025, 5:53 a.m. OK C++20 (GCC 13-64) TESTS 13 77 0
337902424 TimurKul C Sept. 10, 2025, 5:42 a.m. OK C++20 (GCC 13-64) TESTS 13 77 0
337901167 Loloka C Sept. 10, 2025, 5:27 a.m. OK C++20 (GCC 13-64) TESTS 13 77 0
337897183 123xc C Sept. 10, 2025, 4:32 a.m. OK C++20 (GCC 13-64) TESTS 13 77 0
337894440 uyt777 C Sept. 10, 2025, 3:54 a.m. OK C++20 (GCC 13-64) TESTS 13 77 0
337902293 pepperly C Sept. 10, 2025, 5:41 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337899880 so_long C Sept. 10, 2025, 5:10 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337899662 AnkiPro C Sept. 10, 2025, 5:07 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337898876 WjhisTyAhzh C Sept. 10, 2025, 4:56 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337898815 pnhirapara C Sept. 10, 2025, 4:56 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337898709 YangJ1an C Sept. 10, 2025, 4:54 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337898476 ravikumar_ariv C Sept. 10, 2025, 4:51 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337897573 ne0nph4nt0m C Sept. 10, 2025, 4:38 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337895681 IncredibleJ C Sept. 10, 2025, 4:12 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337895603 starflowrain C Sept. 10, 2025, 4:11 a.m. OK C++23 (GCC 14-64, msys2) TESTS 13 77 0
337845156 SIVASRINU_BANDILA021 C Sept. 9, 2025, 4:29 p.m. OK GNU C11 TESTS 13 93 4710400
337846562 kathanshah743 C Sept. 9, 2025, 4:32 p.m. OK GNU C11 TESTS 13 108 4812800
337844764 cfalt.py C Sept. 9, 2025, 4:28 p.m. OK GNU C11 TESTS 13 124 4812800
337842221 SOHAN2358 C Sept. 9, 2025, 4:23 p.m. OK GNU C11 TESTS 13 155 1536000
337840220 gursimarsinghmiglani C Sept. 9, 2025, 4:19 p.m. OK Haskell TESTS 13 421 70348800
337854928 BiggestFish06 C Sept. 9, 2025, 5:33 p.m. OK Java 21 TESTS 13 234 5734400
337894296 ccj123 C Sept. 10, 2025, 3:52 a.m. OK Java 21 TESTS 13 249 819200
337876194 Goutham_808 C Sept. 9, 2025, 9:53 p.m. OK Java 21 TESTS 13 280 819200
337861867 raghavendravelpugonda8 C Sept. 9, 2025, 6:30 p.m. OK Java 21 TESTS 13 281 1638400
337838515 ParthSingla C Sept. 9, 2025, 4:15 p.m. OK Java 21 TESTS 13 296 512000
337879314 chefnav35 C Sept. 9, 2025, 11:01 p.m. OK Java 21 TESTS 13 296 819200
337868020 vatsal_04 C Sept. 9, 2025, 7:36 p.m. OK Java 21 TESTS 13 296 1228800
337875758 mlinear C Sept. 9, 2025, 9:42 p.m. OK Java 21 TESTS 13 296 1740800
337898293 godAngryOver C Sept. 10, 2025, 4:48 a.m. OK Java 21 TESTS 13 296 2150400
337844863 godAngryOver C Sept. 9, 2025, 4:29 p.m. OK Java 21 TESTS 13 327 921600
337862737 public-static-void-main C Sept. 9, 2025, 6:39 p.m. OK Java 8 TESTS 13 186 3379200
337847191 ashuramajestic C Sept. 9, 2025, 4:33 p.m. OK Java 8 TESTS 13 218 3686400
337847873 xmjlove C Sept. 9, 2025, 4:34 p.m. OK Java 8 TESTS 13 233 0
337846831 tarunaggarwal0211 C Sept. 9, 2025, 4:32 p.m. OK Java 8 TESTS 13 233 3686400
337865741 tirthgohil1410 C Sept. 9, 2025, 7:09 p.m. OK Java 8 TESTS 13 233 5836800
337838919 asbro3886 C Sept. 9, 2025, 4:16 p.m. OK Java 8 TESTS 13 249 3584000
337890103 kevin_0911 C Sept. 10, 2025, 2:46 a.m. OK Java 8 TESTS 13 437 0
337866811 saiashish9 C Sept. 9, 2025, 7:22 p.m. OK Java 8 TESTS 13 468 0
337862531 yoyix35296 C Sept. 9, 2025, 6:37 p.m. OK Node.js TESTS 13 249 28160000
337862761 yoyix35296 C Sept. 9, 2025, 6:39 p.m. OK Node.js TESTS 13 249 28364800
337840595 _Zuno_ C Sept. 9, 2025, 4:20 p.m. OK Node.js TESTS 13 375 56729600
337846336 mega_mango C Sept. 9, 2025, 4:31 p.m. OK PyPy 3 TESTS 13 499 18432000
337860000 ibraheemkureshi C Sept. 9, 2025, 6:14 p.m. OK PyPy 3-64 TESTS 13 140 26419200
337858124 kibr C Sept. 9, 2025, 5:58 p.m. OK PyPy 3-64 TESTS 13 155 28364800
337876222 Om_Singh_ C Sept. 9, 2025, 9:54 p.m. OK PyPy 3-64 TESTS 13 156 26521600
337859228 Vespasian_1 C Sept. 9, 2025, 6:07 p.m. OK PyPy 3-64 TESTS 13 171 26726400
337850169 Sycamore_Ma C Sept. 9, 2025, 5:03 p.m. OK PyPy 3-64 TESTS 13 171 27033600
337838310 Sycamore_Ma C Sept. 9, 2025, 4:15 p.m. OK PyPy 3-64 TESTS 13 171 27033600
337871430 ossau C Sept. 9, 2025, 8:21 p.m. OK PyPy 3-64 TESTS 13 171 27443200
337857945 kibr C Sept. 9, 2025, 5:56 p.m. OK PyPy 3-64 TESTS 13 171 28364800
337874350 akshitsinghvi28 C Sept. 9, 2025, 9:12 p.m. OK PyPy 3-64 TESTS 13 171 31436800
337878392 movement124 C Sept. 9, 2025, 10:44 p.m. OK PyPy 3-64 TESTS 13 186 26419200
337844708 Inory C Sept. 9, 2025, 4:28 p.m. OK Python 2 TESTS 13 437 10035200
337878854 MDelPiero C Sept. 9, 2025, 10:53 p.m. OK Python 3 TESTS 13 187 22630400
337879080 ismai C Sept. 9, 2025, 10:57 p.m. OK Python 3 TESTS 13 202 23961600
337856189 coderrg21 C Sept. 9, 2025, 5:42 p.m. OK Python 3 TESTS 13 218 26624000
337860294 Ig_light C Sept. 9, 2025, 6:16 p.m. OK Python 3 TESTS 13 218 26726400
337846125 DT4V C Sept. 9, 2025, 4:31 p.m. OK Python 3 TESTS 13 234 26009600
337853972 amod_24 C Sept. 9, 2025, 5:25 p.m. OK Python 3 TESTS 13 234 26521600
337839506 lioshik_ C Sept. 9, 2025, 4:17 p.m. OK Python 3 TESTS 13 265 26726400
337840860 ous_Sama C Sept. 9, 2025, 4:20 p.m. OK Python 3 TESTS 13 265 28774400
337844001 JosiSol C Sept. 9, 2025, 4:27 p.m. OK Python 3 TESTS 13 280 27443200
337840997 iason_2704 C Sept. 9, 2025, 4:20 p.m. OK Python 3 TESTS 13 296 26521600
337871277 WASDetchan C Sept. 9, 2025, 8:19 p.m. OK Rust 2021 TESTS 13 77 6553600
337853766 i-m-ag-e C Sept. 9, 2025, 5:24 p.m. OK Rust 2021 TESTS 13 77 6553600
337888600 Ckiddo C Sept. 10, 2025, 2:19 a.m. OK Rust 2021 TESTS 13 124 14643200
337857558 vmhung C Sept. 9, 2025, 5:53 p.m. OK Rust 2024 TESTS 13 46 819200
337842543 zhuayhuihan C Sept. 9, 2025, 4:24 p.m. OK Rust 2024 TESTS 13 77 2355200

remove filters

Back to search problems