Codeforces Round 1051 (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
2143 Codeforces Round 1051 (Div. 2) FINISHED False 7200 18285923 Sept. 17, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 20730 ) B Discounts PROGRAMMING greedy sortings two pointers

You want to buy (n) products with prices (a_1, a_2, \ldots, a_n). You can either: buy product (i) individually, paying (a_i) coins, or use a discount voucher to buy it as part of a group purchase. You have (k) discount vouchers with values (b_1, b_2, \ldots, b_k). A voucher of value (x) allows you to select exactly (x) products and pay only for the (x - 1) most expensive ones, as such, you can consider that the cheapest product in the group is free. Each product can be included in at most one discount group, even if it is not the free one. Also, any single voucher can be used at most one single time. What is the minimum total cost required to purchase all (n) products? 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 contains two integers (n) and (k) ((1 \le n, k \le 2 \cdot 10^5)) β€”the number of products and the number of available discount vouchers. The second line contains (n) integers (a_1, a_2, \ldots, a_n) ((1 \le a_i \le 10^9)) β€” the prices of the products. The third line contains (k) integers (b_1, b_2, \ldots, b_k) ((1 \le b_i \le n)) β€” the values of the discount vouchers. It is guaranteed that the sum of (n) across all test cases does not exceed (2 \cdot 10^5), and the sum of (k) across all test cases does not exceed (2 \cdot 10^5). Print (t) lines. The (i)-th line should contain the answer for the (i)-th test case β€” the minimum total cost required to purchase all products in that test case. In the first test case, you can apply the first discount to products 2, 3, and 4. You will pay for the two most expensive ones (3 and 7 coins) and get the cheapest one for free, resulting in a cost of (3 + 7 = 10) coins. Then, apply the second and third discounts to products 1 and 5, getting both for free. The total cost is

Tutorials

Codeforces Round 1051 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
339149153 bharatrajhentaboina B Sept. 17, 2025, 4:16 p.m. OK C# 10 TESTS 10 202 33075200
339142781 mahmudur9 B Sept. 17, 2025, 3:59 p.m. OK C# 13 TESTS 10 203 46899200
339151260 fahimsahriar B Sept. 17, 2025, 4:22 p.m. OK C# 13 TESTS 10 234 38604800
339167747 lamboktulus1379 B Sept. 17, 2025, 6:13 p.m. OK C# 13 TESTS 10 327 68505600
339177966 Ra1nSen B Sept. 17, 2025, 8:09 p.m. OK C++17 (GCC 7-32) TESTS 10 108 102400
339199818 hardikvachhani B Sept. 18, 2025, 3:37 a.m. OK C++17 (GCC 7-32) TESTS 10 109 0
339171594 jadoooo_18 B Sept. 17, 2025, 6:48 p.m. OK C++17 (GCC 7-32) TESTS 10 109 0
339162838 krishnag78 B Sept. 17, 2025, 5:38 p.m. OK C++17 (GCC 7-32) TESTS 10 109 0
339151005 adarshk0508 B Sept. 17, 2025, 4:21 p.m. OK C++17 (GCC 7-32) TESTS 10 109 0
339149333 Seba2010 B Sept. 17, 2025, 4:17 p.m. OK C++17 (GCC 7-32) TESTS 10 109 0
339188535 GhostMFC B Sept. 18, 2025, 12:24 a.m. OK C++17 (GCC 7-32) TESTS 10 109 1638400
339208732 Dhruvin2207 B Sept. 18, 2025, 5:54 a.m. OK C++17 (GCC 7-32) TESTS 10 124 0
339208723 Rccc B Sept. 18, 2025, 5:54 a.m. OK C++17 (GCC 7-32) TESTS 10 124 0
339208285 Osman_001 B Sept. 18, 2025, 5:49 a.m. OK C++17 (GCC 7-32) TESTS 10 124 0
339204785 thiagoyorisbertschi B Sept. 18, 2025, 5:03 a.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339202568 Prefer.P B Sept. 18, 2025, 4:26 a.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339197572 DakshSharma2001 B Sept. 18, 2025, 3:06 a.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339197059 Shakuu B Sept. 18, 2025, 2:59 a.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339191133 yunqi2 B Sept. 18, 2025, 1:25 a.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339190346 ayhamzaidd B Sept. 18, 2025, 1:06 a.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339189028 PiKa_pi B Sept. 18, 2025, 12:36 a.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339185905 MohZoro B Sept. 17, 2025, 11:12 p.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339183852 zero_0000 B Sept. 17, 2025, 10:09 p.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339178825 pradyumnkangule B Sept. 17, 2025, 8:23 p.m. OK C++20 (GCC 13-64) TESTS 10 93 0
339209842 hiba_ak06 B Sept. 18, 2025, 6:06 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339207880 edavidpham B Sept. 18, 2025, 5:45 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339206858 RuinGuard B Sept. 18, 2025, 5:32 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339205293 yuanxiao7 B Sept. 18, 2025, 5:12 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339202931 Spicy_Syntax B Sept. 18, 2025, 4:32 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339201588 prajwal311 B Sept. 18, 2025, 4:07 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339199162 LostFrequency B Sept. 18, 2025, 3:26 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339198153 __90m3 B Sept. 18, 2025, 3:13 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339197812 _mustafo_ B Sept. 18, 2025, 3:09 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339197144 chancholkumar384 B Sept. 18, 2025, 3 a.m. OK C++23 (GCC 14-64, msys2) TESTS 10 93 0
339207143 SANDEEP6481 B Sept. 18, 2025, 5:36 a.m. OK GNU C11 TESTS 10 124 1536000
339147146 monish1406 B Sept. 17, 2025, 4:11 p.m. OK GNU C11 TESTS 10 124 1536000
339146909 Ch4Os B Sept. 17, 2025, 4:10 p.m. OK GNU C11 TESTS 10 124 1638400
339151065 DeAdminVil B Sept. 17, 2025, 4:22 p.m. OK GNU C11 TESTS 10 124 2457600
339144965 SOHAN2358 B Sept. 17, 2025, 4:05 p.m. OK GNU C11 TESTS 10 125 4096000
339146004 hrushikesh_bhaw B Sept. 17, 2025, 4:08 p.m. OK GNU C11 TESTS 10 139 1536000
339145143 logicsolver B Sept. 17, 2025, 4:05 p.m. OK GNU C11 TESTS 10 155 1536000
339150956 karma25 B Sept. 17, 2025, 4:21 p.m. OK GNU C11 TESTS 10 155 2355200
339147112 nirvik_23 B Sept. 17, 2025, 4:11 p.m. OK GNU C11 TESTS 10 155 3072000
339152906 amar103 B Sept. 17, 2025, 4:27 p.m. OK Java 21 TESTS 10 265 614400
339202015 divyanshnm B Sept. 18, 2025, 4:15 a.m. OK Java 21 TESTS 10 343 2048000
339155898 SamPendam B Sept. 17, 2025, 4:34 p.m. OK Java 21 TESTS 10 374 716800
339146472 mishraambar973 B Sept. 17, 2025, 4:09 p.m. OK Java 21 TESTS 10 374 2560000
339154334 Pssikriwal_47 B Sept. 17, 2025, 4:30 p.m. OK Java 21 TESTS 10 374 4300800
339200969 priyaroy3370 B Sept. 18, 2025, 3:56 a.m. OK Java 21 TESTS 10 374 11571200
339153126 Yash_datoniya B Sept. 17, 2025, 4:27 p.m. OK Java 21 TESTS 10 389 4300800
339154505 praveen_058 B Sept. 17, 2025, 4:31 p.m. OK Java 21 TESTS 10 389 6451200
339162345 Aditya_17_08_04 B Sept. 17, 2025, 5:34 p.m. OK Java 21 TESTS 10 390 2048000
339164531 ajikhoji B Sept. 17, 2025, 5:49 p.m. OK Java 21 TESTS 10 390 3584000
339154093 bhawnapannu27 B Sept. 17, 2025, 4:30 p.m. OK Java 8 TESTS 10 187 0
339191579 Michael180 B Sept. 18, 2025, 1:35 a.m. OK Java 8 TESTS 10 249 9728000
339169679 sarthaKKharKa_18 B Sept. 17, 2025, 6:29 p.m. OK Java 8 TESTS 10 280 10956800
339172444 hiddenhopes B Sept. 17, 2025, 6:57 p.m. OK Java 8 TESTS 10 312 20377600
339147905 liuning123 B Sept. 17, 2025, 4:13 p.m. OK Java 8 TESTS 10 327 19558400
339167447 abhayrajnegi0416 B Sept. 17, 2025, 6:11 p.m. OK Java 8 TESTS 10 328 11980800
339161472 yashvardhan3 B Sept. 17, 2025, 5:29 p.m. OK Java 8 TESTS 10 343 11776000
339153613 tarunaggarwal0211 B Sept. 17, 2025, 4:28 p.m. OK Java 8 TESTS 10 358 8294400
339166572 Ashu2030 B Sept. 17, 2025, 6:04 p.m. OK Java 8 TESTS 10 390 10752000
339144768 Kimximya1 B Sept. 17, 2025, 4:04 p.m. OK Java 8 TESTS 10 421 3276800
339154296 A_23 B Sept. 17, 2025, 4:30 p.m. OK Kotlin 1.9 TESTS 10 640 6246400
339165202 A_23 B Sept. 17, 2025, 5:54 p.m. OK Kotlin 1.9 TESTS 10 733 26521600
339164545 A_23 B Sept. 17, 2025, 5:49 p.m. OK Kotlin 1.9 TESTS 10 734 26419200
339161000 L-S-S B Sept. 17, 2025, 5:26 p.m. OK Kotlin 2.2 TESTS 10 499 26009600
339178279 swseverance B Sept. 17, 2025, 8:14 p.m. OK Node.js TESTS 10 531 82227200
339167296 profenc1ng B Sept. 17, 2025, 6:09 p.m. OK PyPy 2 TESTS 10 249 19865600
339150925 Cyros B Sept. 17, 2025, 4:21 p.m. OK PyPy 2 TESTS 10 624 28467200
339146447 Dangerous_Coder_69 B Sept. 17, 2025, 4:09 p.m. OK PyPy 3 TESTS 10 421 18534400
339155287 utsab77 B Sept. 17, 2025, 4:33 p.m. OK PyPy 3 TESTS 10 421 21913600
339142918 Akillove B Sept. 17, 2025, 3:59 p.m. OK PyPy 3 TESTS 10 499 20992000
339203833 _PD_ B Sept. 18, 2025, 4:49 a.m. OK PyPy 3 TESTS 10 530 25190400
339154651 adityakudale2712 B Sept. 17, 2025, 4:31 p.m. OK PyPy 3 TESTS 10 624 22323200
339197024 rank007 B Sept. 18, 2025, 2:58 a.m. OK PyPy 3-64 TESTS 10 186 28876800
339145153 aa_despa B Sept. 17, 2025, 4:05 p.m. OK PyPy 3-64 TESTS 10 186 29593600
339201987 gardengnome B Sept. 18, 2025, 4:14 a.m. OK PyPy 3-64 TESTS 10 187 27136000
339146439 M_M_Pruthvi_Raj B Sept. 17, 2025, 4:09 p.m. OK PyPy 3-64 TESTS 10 187 29184000
339174301 hackedx042345 B Sept. 17, 2025, 7:19 p.m. OK PyPy 3-64 TESTS 10 187 32460800
339185354 mathsplanck B Sept. 17, 2025, 10:55 p.m. OK PyPy 3-64 TESTS 10 187 46080000
339178403 HelloGoodbye B Sept. 17, 2025, 8:16 p.m. OK PyPy 3-64 TESTS 10 202 31232000
339153325 shivamsai006 B Sept. 17, 2025, 4:28 p.m. OK PyPy 3-64 TESTS 10 202 45670400
339199434 additionalpass05 B Sept. 18, 2025, 3:30 a.m. OK PyPy 3-64 TESTS 10 203 33075200
339189219 LeoXLia B Sept. 18, 2025, 12:40 a.m. OK PyPy 3-64 TESTS 10 217 28979200
339204841 taagcgaat B Sept. 18, 2025, 5:04 a.m. OK Python 3 TESTS 10 202 28569600
339143733 pc91 B Sept. 17, 2025, 4:01 p.m. OK Python 3 TESTS 10 202 31744000
339151551 adhilkv313 B Sept. 17, 2025, 4:23 p.m. OK Python 3 TESTS 10 202 41472000
339148832 Aditya_Lallchandani B Sept. 17, 2025, 4:15 p.m. OK Python 3 TESTS 10 217 31436800
339155203 maharship343 B Sept. 17, 2025, 4:32 p.m. OK Python 3 TESTS 10 218 29081600
339155416 dhanushracharla777 B Sept. 17, 2025, 4:33 p.m. OK Python 3 TESTS 10 218 31436800
339198884 need_thing B Sept. 18, 2025, 3:23 a.m. OK Python 3 TESTS 10 218 31744000
339152233 modiharsh93 B Sept. 17, 2025, 4:25 p.m. OK Python 3 TESTS 10 218 31744000
339150509 DoublePower B Sept. 17, 2025, 4:20 p.m. OK Python 3 TESTS 10 218 31744000
339147964 mylavaramsai B Sept. 17, 2025, 4:13 p.m. OK Python 3 TESTS 10 218 31744000
339146206 sankxt143 B Sept. 17, 2025, 4:08 p.m. OK Rust 2021 TESTS 10 93 3584000
339150477 AnuragYADAV_10 B Sept. 17, 2025, 4:20 p.m. OK Rust 2024 TESTS 10 77 5222400

remove filters

Back to search problems