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 |
|---|---|---|---|---|---|---|
| 2055 | Codeforces Round 996 (Div. 2) | FINISHED | False | 7200 | 39713123 | Jan. 12, 2025, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 470 ) | E | Haystacks | PROGRAMMING | constructive algorithms data structures greedy |
There are (n) haystacks labelled from (1) to (n), where haystack (i) contains (a_i) haybales. One of the haystacks has a needle hidden beneath it, but you do not know which one. Your task is to move the haybales so that each haystack is emptied at least once, allowing you to check if the needle is hidden under that particular haystack. However, the process is not that simple. Once a haystack (i) is emptied for the first time, it will be assigned a height limit and can no longer contain more than (b_i) haybales. More formally, a move is described as follows: Choose two haystacks (i) and (j). If haystack (i) has not been emptied before, or haystack (i) contains strictly less than (b_i) haybales, you may move exactly (1) haybale from haystack (j) to haystack (i). Note : Before a haystack is emptied, it has no height limit, and you can move as many haybales as you want onto that haystack. Compute the minimum number of moves required to ensure that each haystack is emptied at least once, or report that it is impossible. 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) ((2\le n\le 5\cdot 10^5)) — the number of haystacks. The (i)-th of the next (n) lines contains two integers (a_i) and (b_i) ((1\le a_i, b_i\le 10^9)) — the initial number of haybales in the (i)-th haystack, and the height limit that it is assigned after it is emptied for the first time. It is guaranteed that the sum of (n) over all test cases does not exceed (5 \cdot 10^5). For each test case, print a single integer — the minimum number of moves required to ensure that each haystack is emptied at least once. If it is not possible to empty each haystack at least once, output -1 . In the first test case, we can do the follow |
| Codeforces Round 996 (Div. 2) Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 300773277 | DeadlyCritic | E | Jan. 12, 2025, 11:47 p.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 327 | 12492800 | ||
| 300774590 | DeadlyCritic | E | Jan. 13, 2025, 12:43 a.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 343 | 16486400 | ||
| 300739410 | liympanda | E | Jan. 12, 2025, 4:19 p.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 390 | 11776000 | ||
| 300780090 | TianyiWei | E | Jan. 13, 2025, 3 a.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 406 | 24064000 | ||
| 300770071 | riverwalk7 | E | Jan. 12, 2025, 9:53 p.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 437 | 16384000 | ||
| 300770483 | amirhoseinfar1385 | E | Jan. 12, 2025, 10:05 p.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 483 | 16384000 | ||
| 300779905 | ggg | E | Jan. 13, 2025, 2:57 a.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 499 | 54169600 | ||
| 300763977 | BenjaminJ | E | Jan. 12, 2025, 7:49 p.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 655 | 21299200 | ||
| 300784956 | jcelin | E | Jan. 13, 2025, 4:14 a.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 702 | 24883200 | ||
| 300770105 | tmwilliamlin168 | E | Jan. 12, 2025, 9:54 p.m. | OK | C++17 (GCC 7-32) | TESTS | 115 | 874 | 42905600 | ||
| 300779110 | Zhu_Yuanzhang | E | Jan. 13, 2025, 2:41 a.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 140 | 12390400 | ||
| 300780408 | enslaved | E | Jan. 13, 2025, 3:05 a.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 265 | 18227200 | ||
| 300775828 | anhkha1004 | E | Jan. 13, 2025, 1:23 a.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 281 | 12390400 | ||
| 300777777 | ahsoltan | E | Jan. 13, 2025, 2:12 a.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 296 | 12083200 | ||
| 300740253 | kotatsugame | E | Jan. 12, 2025, 4:21 p.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 296 | 17715200 | ||
| 300768896 | A_G | E | Jan. 12, 2025, 9:23 p.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 312 | 16384000 | ||
| 300770683 | tin.le2 | E | Jan. 12, 2025, 10:11 p.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 312 | 20377600 | ||
| 300770583 | tin.le2 | E | Jan. 12, 2025, 10:08 p.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 312 | 20377600 | ||
| 300769926 | tin.le2 | E | Jan. 12, 2025, 9:49 p.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 327 | 20377600 | ||
| 300756115 | Brahmendra06 | E | Jan. 12, 2025, 6:19 p.m. | OK | C++20 (GCC 13-64) | TESTS | 115 | 327 | 24166400 | ||
| 300757177 | AgafonovArtem | E | Jan. 12, 2025, 6:28 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 296 | 12492800 | ||
| 300783004 | tfg | E | Jan. 13, 2025, 3:48 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 296 | 16486400 | ||
| 300777301 | pengpeng_fudan | E | Jan. 13, 2025, 2 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 296 | 16486400 | ||
| 300754757 | threebody4 | E | Jan. 12, 2025, 6:07 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 311 | 8499200 | ||
| 300783935 | Normalizerr | E | Jan. 13, 2025, 4 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 327 | 28569600 | ||
| 300783506 | Normalizerr | E | Jan. 13, 2025, 3:54 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 327 | 28569600 | ||
| 300762840 | SHKAV | E | Jan. 12, 2025, 7:34 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 327 | 42700800 | ||
| 300753066 | SHKAV | E | Jan. 12, 2025, 5:54 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 327 | 42700800 | ||
| 300762805 | SHKAV | E | Jan. 12, 2025, 7:33 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 374 | 42496000 | ||
| 300786609 | krit3379 | E | Jan. 13, 2025, 4:38 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 115 | 421 | 21299200 | ||
| 300771983 | rainboy | E | Jan. 12, 2025, 10:55 p.m. | OK | GNU C11 | TESTS | 115 | 327 | 18124800 | ||
| 300770442 | arvindf232 | E | Jan. 12, 2025, 10:03 p.m. | OK | Kotlin 1.7 | TESTS | 115 | 1733 | 165888000 | ||
| 300770044 | arvindf232 | E | Jan. 12, 2025, 9:52 p.m. | OK | Kotlin 1.7 | TESTS | 115 | 1936 | 160256000 | ||
| 300769323 | arvindf232 | E | Jan. 12, 2025, 9:34 p.m. | OK | Kotlin 1.7 | TESTS | 115 | 1953 | 168448000 | ||
| 300743652 | arvindf232 | E | Jan. 12, 2025, 4:28 p.m. | OK | Kotlin 1.7 | TESTS | 115 | 1999 | 166707200 | ||
| 300773125 | CDastrup | E | Jan. 12, 2025, 11:41 p.m. | OK | PyPy 3-64 | TESTS | 115 | 1733 | 68403200 |
Back to search problems