Codeforces Round 1064 (Div. 1)

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
2165 Codeforces Round 1064 (Div. 1) FINISHED False 7200 13101923 Nov. 16, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 13965 ) A Cyclic Merging PROGRAMMING brute force constructive algorithms graphs greedy trees

You are given (n) non-negative integers (a_1,a_2,\ldots,a_n) arranged on a ring. For each (1\le i< n), (a_i) and (a_{i+1}) are adjacent; (a_1) and (a_n) are adjacent. You need to perform the following operation exactly (n-1) times: Choose any pair of adjacent elements on the ring, let their values be (x) and (y), and merge them into a single element of value (\max(x,y)) with cost (\max(x,y)). Note that this operation will decrease the size of the ring by (1) and update the adjacent relationships accordingly. Please calculate the minimum total cost to merge the ring into one element. 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) ((2\le n\le 2\cdot 10^5)). The following line contains (n) integers (a_1,a_2,\ldots,a_n) ((0\le a_i \le 10^9)). It is guaranteed that the sum of (n) over all test cases does not exceed (2\cdot 10^5). For each test case, please print a single integer — the minimum total cost. In the first test case, we can achieve a cost of (6) on (1,1,3,2) as follows: Merge indexes (1) and (2) with a cost of (1), the ring becomes (1,3,2). Merge indexes (1) and (3) with a cost of (2), the ring becomes (3,2). Merge indexes (1) and (2) with a cost of (3), the ring becomes (3). The total cost is (1+2+3=6). It can be proven that it is impossible to achieve a lower cost; thus, the answer is indeed (6). In the second test case, the only option is to merge the two elements, with a cost of (2).

Tutorials

148452

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
349277685 -firefly- A Nov. 16, 2025, 2:42 p.m. OK C# 13 TESTS 20 218 5324800
349278378 oceeff A Nov. 16, 2025, 2:43 p.m. OK C++17 (GCC 7-32) TESTS 20 78 4710400
349278218 Gold14526 A Nov. 16, 2025, 2:43 p.m. OK C++17 (GCC 7-32) TESTS 20 92 4505600
349277906 mircea_007 A Nov. 16, 2025, 2:42 p.m. OK C++17 (GCC 7-32) TESTS 20 93 0
349380863 Kurosaki__Ichigo A Nov. 17, 2025, 6:10 a.m. OK C++17 (GCC 7-32) TESTS 20 93 0
349375246 Ammar.IT A Nov. 17, 2025, 5:07 a.m. OK C++17 (GCC 7-32) TESTS 20 93 0
349365990 .dabaww44 A Nov. 17, 2025, 3:13 a.m. OK C++17 (GCC 7-32) TESTS 20 93 101785600
349329361 SauravKmr A Nov. 16, 2025, 5:27 p.m. OK C++17 (GCC 7-32) TESTS 20 108 0
349275496 balatro A Nov. 16, 2025, 2:39 p.m. OK C++17 (GCC 7-32) TESTS 20 108 1638400
349283505 ABCaCaCa_ A Nov. 16, 2025, 2:51 p.m. OK C++17 (GCC 7-32) TESTS 20 108 6451200
349380465 2023wangzhaolan A Nov. 17, 2025, 6:06 a.m. OK C++17 (GCC 7-32) TESTS 20 108 7987200
349280115 catologistics A Nov. 16, 2025, 2:46 p.m. OK C++20 (GCC 13-64) TESTS 20 77 2150400
349368662 yunzheqiao06930 A Nov. 17, 2025, 3:47 a.m. OK C++20 (GCC 13-64) TESTS 20 78 0
349280354 www_bilibili_com A Nov. 16, 2025, 2:46 p.m. OK C++20 (GCC 13-64) TESTS 20 78 4096000
349278839 Depressed_sad_boy A Nov. 16, 2025, 2:44 p.m. OK C++20 (GCC 13-64) TESTS 20 92 0
349278351 MYJBCHX A Nov. 16, 2025, 2:43 p.m. OK C++20 (GCC 13-64) TESTS 20 92 28467200
349279678 o7ro A Nov. 16, 2025, 2:45 p.m. OK C++20 (GCC 13-64) TESTS 20 93 0
349292092 Apteryxx A Nov. 16, 2025, 3:07 p.m. OK C++20 (GCC 13-64) TESTS 20 93 0
349291342 sam990 A Nov. 16, 2025, 3:05 p.m. OK C++20 (GCC 13-64) TESTS 20 93 0
349280270 0471740 A Nov. 16, 2025, 2:46 p.m. OK C++20 (GCC 13-64) TESTS 20 93 0
349279620 FlowerandYou A Nov. 16, 2025, 2:45 p.m. OK C++20 (GCC 13-64) TESTS 20 93 0
349287440 madtreap A Nov. 16, 2025, 2:58 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 0
349370125 Camellia_Tender A Nov. 17, 2025, 4:02 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 0
349337658 LuoxuanLove A Nov. 16, 2025, 6:39 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 0
349334665 Shreshtha_Max A Nov. 16, 2025, 6:12 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 0
349329817 0mar_1 A Nov. 16, 2025, 5:31 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 0
349276489 miscalculation53 A Nov. 16, 2025, 2:40 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 307200
349276644 cooluo A Nov. 16, 2025, 2:41 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 3788800
349368852 Fakewave A Nov. 17, 2025, 3:49 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 0
349352686 Blinov_Artemii A Nov. 16, 2025, 10:23 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 78 2048000
349368553 142 A Nov. 17, 2025, 3:46 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 92 0
349283685 khuepr123 A Nov. 16, 2025, 2:52 p.m. OK Haskell TESTS 20 171 23244800
349286392 nathanballman A Nov. 16, 2025, 2:56 p.m. OK Java 21 TESTS 20 421 1433600
349278623 anshwww A Nov. 16, 2025, 2:44 p.m. OK Java 21 TESTS 20 515 6758400
349279776 iamalizaidi A Nov. 16, 2025, 2:45 p.m. OK Java 21 TESTS 20 842 16793600
349279463 gua069 A Nov. 16, 2025, 2:45 p.m. OK Java 8 TESTS 20 765 9011200
349275093 Tlatoani A Nov. 16, 2025, 2:39 p.m. OK Kotlin 2.2 TESTS 20 937 34099200
349275748 Broder A Nov. 16, 2025, 2:40 p.m. OK PyPy 3 TESTS 20 702 21504000
349343746 Satishrao5 A Nov. 16, 2025, 7:49 p.m. OK PyPy 3-64 TESTS 20 139 26521600
349345575 thakurchinmay10 A Nov. 16, 2025, 8:14 p.m. OK PyPy 3-64 TESTS 20 140 29388800
349285183 kdy8128 A Nov. 16, 2025, 2:54 p.m. OK PyPy 3-64 TESTS 20 155 26624000
349276592 gawkmaster069 A Nov. 16, 2025, 2:41 p.m. OK PyPy 3-64 TESTS 20 155 26624000
349288071 eepsilon A Nov. 16, 2025, 2:59 p.m. OK PyPy 3-64 TESTS 20 171 26624000
349279916 happybear21 A Nov. 16, 2025, 2:46 p.m. OK PyPy 3-64 TESTS 20 171 29388800
349274439 Nolirue_Sola A Nov. 16, 2025, 2:38 p.m. OK PyPy 3-64 TESTS 20 186 27136000
349290705 SnowballSH A Nov. 16, 2025, 3:04 p.m. OK PyPy 3-64 TESTS 20 202 26521600
349366691 smilences A Nov. 17, 2025, 3:25 a.m. OK PyPy 3-64 TESTS 20 202 26624000
349361976 M.AbdurRehman A Nov. 17, 2025, 2 a.m. OK PyPy 3-64 TESTS 20 202 26624000
349278040 ACr0bat A Nov. 16, 2025, 2:43 p.m. OK Python 3 TESTS 20 218 26316800
349275757 sansen A Nov. 16, 2025, 2:40 p.m. OK Rust 2021 TESTS 20 77 1024000
349279418 Monster027 A Nov. 16, 2025, 2:45 p.m. OK Rust 2024 TESTS 20 92 614400
349277409 null_lambda A Nov. 16, 2025, 2:42 p.m. OK Rust 2024 TESTS 20 264 7884800

remove filters

Back to search problems