Codeforces Round 1097 (Div. 2, Based on Zhili Cup 2026)

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
2224 Codeforces Round 1097 (Div. 2, Based on Zhili Cup 2026) FINISHED False 9000 3282906 May 6, 2026, 6:05 a.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 7723 ) B Zhily and Mex and Max PROGRAMMING constructive algorithms greedy math sortings

Deeper in the wilderness, Zhily and Jily discovered a mysterious sequence of numbers. Each prefix of the sequence has an important characteristic value, known as the mex and the max. By rearranging the sequence, it can generate a special kind of magic. You are given an array (a) of (n) non-negative integers. You can rearrange it arbitrarily. Find the maximum possible value of the sum of the MEX(^{\text{∗}}) and the maximum value over all prefixes. Formally, you need to maximize the following expression: (\sum\limits_{i=1}^n (\operatorname{mex}(a_1,a_2,\cdots,a_i)+\max(a_1,a_2,\cdots,a_i))). (^{\text{∗}})The minimum excluded (MEX) of a collection of integers (c_1, c_2, \ldots, c_k) is defined as the smallest non-negative integer (x) which does not occur in the collection (c). 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 \leq n \leq 2\cdot 10^5)) — the length of the array (a). The second line contains (n) integers (a_1,a_2,\cdots,a_n) ((0\leq a_i \leq 10^9)) — the array (a). It is guaranteed that the sum of (n) over all test cases does not exceed (2\cdot 10^5). For each test case, output the maximum sum on a new line. In the first test case, no matter how you rearrange (a), the MEX and the maximum value for each prefix will always be (1) and (0), respectively. In the third test case, you can rearrange (a) into (0,1,1,1,1), so that (\sum\limits_{i=1}^n (\operatorname{mex}(a_1,a_2,\cdots,a_i)+\max(a_1,a_2,\cdots,a_i))=(1+0)+(2+1)+(2+1)+(2+1)+(2+1)=13). It can be shown that this is the optimal solution.

Tutorials

Codeforces Round 1097 (Div. 1, Div2, Based on Zhili Cup 2026) Tutorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
373678545 sasafied B May 6, 2026, 7:30 a.m. OK C# 10 TESTS 5 78 1638400
373692254 Yesha-Y B May 6, 2026, 8:34 a.m. OK C++17 (GCC 7-32) TESTS 5 46 0
373687605 linweiway67 B May 6, 2026, 8:15 a.m. OK C++17 (GCC 7-32) TESTS 5 46 0
373680643 curriedham B May 6, 2026, 7:40 a.m. OK C++17 (GCC 7-32) TESTS 5 46 0
373760772 Kha1e1 B May 6, 2026, 7:59 p.m. OK C++17 (GCC 7-32) TESTS 5 62 0
373737045 N1KlTA B May 6, 2026, 3:23 p.m. OK C++17 (GCC 7-32) TESTS 5 62 0
373725463 kinshuk7 B May 6, 2026, 1:46 p.m. OK C++17 (GCC 7-32) TESTS 5 62 0
373725320 traits_101 B May 6, 2026, 1:44 p.m. OK C++17 (GCC 7-32) TESTS 5 62 0
373712782 Sunlet_orz B May 6, 2026, 12:03 p.m. OK C++17 (GCC 7-32) TESTS 5 62 0
373709493 Yihaodong B May 6, 2026, 11:35 a.m. OK C++17 (GCC 7-32) TESTS 5 62 0
373706168 MelodicOctopus B May 6, 2026, 11:03 a.m. OK C++17 (GCC 7-32) TESTS 5 62 0
373678109 fdasgreag B May 6, 2026, 7:28 a.m. OK C++20 (GCC 13-64) TESTS 5 31 2150400
373734189 fghjyd B May 6, 2026, 3 p.m. OK C++20 (GCC 13-64) TESTS 5 46 0
373722509 QF0205 B May 6, 2026, 1:22 p.m. OK C++20 (GCC 13-64) TESTS 5 46 0
373714214 Kamikazee112 B May 6, 2026, 12:15 p.m. OK C++20 (GCC 13-64) TESTS 5 46 0
373704323 Atharv578 B May 6, 2026, 10:42 a.m. OK C++20 (GCC 13-64) TESTS 5 46 0
373685918 Fouzia_khan B May 6, 2026, 8:06 a.m. OK C++20 (GCC 13-64) TESTS 5 46 0
373739304 Bitwise_Mind B May 6, 2026, 3:43 p.m. OK C++20 (GCC 13-64) TESTS 5 46 102400
373682021 sripragnaneti B May 6, 2026, 7:47 a.m. OK C++20 (GCC 13-64) TESTS 5 46 102400
373771376 HXYDSG B May 7, 2026, 1:19 a.m. OK C++20 (GCC 13-64) TESTS 5 62 0
373756150 piyushcool26 B May 6, 2026, 6:37 p.m. OK C++20 (GCC 13-64) TESTS 5 62 0
373768834 puspender_Y008 B May 6, 2026, 11:52 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373767284 Papiba B May 6, 2026, 10:54 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373759099 CosmicX2 B May 6, 2026, 7:26 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373756140 ham727 B May 6, 2026, 6:37 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373753511 navadeep2801 B May 6, 2026, 6:06 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373748639 NomNomFull B May 6, 2026, 5:17 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373742091 amazonanios B May 6, 2026, 4:10 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373738744 HridayVirat_18 B May 6, 2026, 3:38 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373738261 cdd B May 6, 2026, 3:34 p.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373702427 xiaowang524 B May 6, 2026, 10:20 a.m. OK C++23 (GCC 14-64, msys2) TESTS 5 46 0
373774891 ruban B May 7, 2026, 2:58 a.m. OK FPC TESTS 5 62 52838400
373682022 coder_seasoned B May 6, 2026, 7:47 a.m. OK GNU C11 TESTS 5 62 716800
373698757 baili_water B May 6, 2026, 9:39 a.m. OK GNU C11 TESTS 5 62 819200
373733685 K-Squared B May 6, 2026, 2:56 p.m. OK GNU C11 TESTS 5 62 5324800
373682399 youlinaixv B May 6, 2026, 7:49 a.m. OK GNU C11 TESTS 5 78 614400
373742428 vedjaw B May 6, 2026, 4:13 p.m. OK GNU C11 TESTS 5 78 1228800
373681338 BenriLap B May 6, 2026, 7:44 a.m. OK GNU C11 TESTS 5 78 1536000
373678733 frag_ B May 6, 2026, 7:31 a.m. OK GNU C11 TESTS 5 78 1536000
373676019 ___Abdoo___ B May 6, 2026, 7:20 a.m. OK GNU C11 TESTS 5 93 3276800
373687602 123fdr B May 6, 2026, 8:15 a.m. OK GNU C11 TESTS 5 468 1536000
373685675 goodsmellmoutainpeople B May 6, 2026, 8:05 a.m. OK Go TESTS 5 109 3276800
373727891 link1k B May 6, 2026, 2:06 p.m. OK Go TESTS 5 109 10137600
373751549 prajas_004 B May 6, 2026, 5:45 p.m. OK Go TESTS 5 109 37068800
373711544 MD_Morshed_Jaman B May 6, 2026, 11:53 a.m. OK Java 21 TESTS 5 156 409600
373696752 code_manik B May 6, 2026, 9:19 a.m. OK Java 21 TESTS 5 218 614400
373678009 __0xCk__ B May 6, 2026, 7:28 a.m. OK Java 21 TESTS 5 234 204800
373772657 Azad_Singh B May 7, 2026, 1:59 a.m. OK Java 21 TESTS 5 234 512000
373687147 S0haib B May 6, 2026, 8:12 a.m. OK Java 21 TESTS 5 234 614400
373685729 sanskarvarshney12 B May 6, 2026, 8:05 a.m. OK Java 21 TESTS 5 234 614400
373710079 madhu.korada131 B May 6, 2026, 11:40 a.m. OK Java 21 TESTS 5 234 5120000
373707950 mank_1008 B May 6, 2026, 11:21 a.m. OK Java 21 TESTS 5 250 512000
373675847 RAVEYUS B May 6, 2026, 7:19 a.m. OK Java 21 TESTS 5 250 819200
373706403 raunakktiwari42 B May 6, 2026, 11:05 a.m. OK Java 21 TESTS 5 281 3174400
373731675 simran_001 B May 6, 2026, 2:39 p.m. OK Java 8 TESTS 5 93 0
373689189 asahasra66 B May 6, 2026, 8:22 a.m. OK Java 8 TESTS 5 156 0
373675990 sangramofc B May 6, 2026, 7:19 a.m. OK Java 8 TESTS 5 187 2252800
373682862 mdsadiqueshakeel B May 6, 2026, 7:52 a.m. OK Java 8 TESTS 5 265 3584000
373676615 _sitesh_kumar B May 6, 2026, 7:22 a.m. OK Java 8 TESTS 5 328 5120000
373752904 nikhil97agra B May 6, 2026, 5:59 p.m. OK Java 8 TESTS 5 437 11878400
373677679 nishita_v B May 6, 2026, 7:27 a.m. OK Java 8 TESTS 5 484 6451200
373676220 sirola B May 6, 2026, 7:20 a.m. OK Java 8 TESTS 5 578 2457600
373676911 jsaddict044 B May 6, 2026, 7:23 a.m. OK PyPy 3 TESTS 5 187 14336000
373682034 loveax B May 6, 2026, 7:47 a.m. OK PyPy 3 TESTS 5 265 24985600
373737368 wakabo B May 6, 2026, 3:26 p.m. OK PyPy 3 TESTS 5 281 11673600
373736420 wakabo B May 6, 2026, 3:18 p.m. OK PyPy 3 TESTS 5 281 11673600
373682413 kirnau17 B May 6, 2026, 7:49 a.m. OK PyPy 3 TESTS 5 312 11673600
373681885 mirkocoric B May 6, 2026, 7:47 a.m. OK PyPy 3-64 TESTS 5 93 17100800
373774220 Viveksarathe B May 7, 2026, 2:40 a.m. OK PyPy 3-64 TESTS 5 93 17715200
373763310 aryan_shah26 B May 6, 2026, 8:59 p.m. OK PyPy 3-64 TESTS 5 93 18944000
373711227 Aspiring_chocker B May 6, 2026, 11:50 a.m. OK PyPy 3-64 TESTS 5 93 19558400
373768581 masao B May 6, 2026, 11:43 p.m. OK PyPy 3-64 TESTS 5 109 17920000
373682311 Z_i_a_d_M_G_25 B May 6, 2026, 7:49 a.m. OK PyPy 3-64 TESTS 5 109 18534400
373690565 unseen_Dracula_07 B May 6, 2026, 8:28 a.m. OK PyPy 3-64 TESTS 5 109 18944000
373690349 nickindian07 B May 6, 2026, 8:27 a.m. OK PyPy 3-64 TESTS 5 109 18944000
373680124 scooley B May 6, 2026, 7:38 a.m. OK PyPy 3-64 TESTS 5 109 19763200
373766456 explainer B May 6, 2026, 10:28 p.m. OK PyPy 3-64 TESTS 5 125 19046400
373722128 KJJjjjdah B May 6, 2026, 1:19 p.m. OK Python 3 TESTS 5 78 26726400
373699001 Rhnvrma B May 6, 2026, 9:42 a.m. OK Python 3 TESTS 5 125 13824000
373681797 providerbsc B May 6, 2026, 7:46 a.m. OK Python 3 TESTS 5 125 13926400
373689212 bdv B May 6, 2026, 8:22 a.m. OK Python 3 TESTS 5 125 16179200
373698087 LEO__1101 B May 6, 2026, 9:31 a.m. OK Python 3 TESTS 5 125 22732800
373727112 Hanyun B May 6, 2026, 2 p.m. OK Python 3 TESTS 5 125 26316800
373677420 Soundarya_Dube B May 6, 2026, 7:25 a.m. OK Python 3 TESTS 5 140 13824000
373770676 chmpro B May 7, 2026, 12:58 a.m. OK Python 3 TESTS 5 140 14028800
373694671 Dharmik31 B May 6, 2026, 9:01 a.m. OK Python 3 TESTS 5 171 16179200
373714402 bai1013 B May 6, 2026, 12:17 p.m. OK Python 3 TESTS 5 203 20684800
373750640 cvs-650 B May 6, 2026, 5:37 p.m. OK Rust 2024 TESTS 5 62 3174400

remove filters

Back to search problems