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 |
|---|---|---|---|---|---|---|
| 2141 | Kotlin Heroes: Episode 13 | FINISHED | False | 9000 | 18717923 | Sept. 12, 2025, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 469 ) | D | Avoid Minimums | PROGRAMMING | *special greedy math |
You are given an integer array (a_1, a_2, a_3, \dots, a_n). Your task is to make all elements of (a) equal. In order to do it, you can perform the following operation at most (k) times: choose any index (i) from (1) to (n) and increase (a_i) by one. What is the maximum number of coins you can earn among all possible ways to make the array equal? The first line contains one integer (t) ((1 \le t \le 1000)) — the number of test cases. Next, (t) cases follow (all cases are independent). The first line of each test case contains two integers (n) and (k) ((2 \le n \le 3 \cdot 10^5); (1 \le k \le 10^{12})) — the size of array (a) and the maximum number of operations you can perform. The second line contains (n) integers (a_1, a_2, \dots, a_n) ((1 \le a_i \le 10^9)) — the array itself. It's guaranteed that the total sum of (n) over all test cases doesn't exceed (3 \cdot 10^5). For each test case, if it's impossible to make all elements equal, print (-1). Otherwise, print the maximum number of coins you can earn while making all elements equal. In the first test case, you need at least (17) operations to make all elements equal (or to get the array (10, 10, 10)). In the second test case, you can, for example, increase (a_3 = 4) to (10), then increase (a_1 = 6) to (10), after that increase (a_4 = 9) to (10) and, finally, (a_2 = 2) to (10). You'll perform (19) operations and earn ((10 - 4) + (10 - 6) + (10 - 9) = 11) coins in total, since increasing the (a_2) from (2) to (10) won't give you any coins. In the third test case, you can leave the array unchanged or make all elements equal to (8) — both strategies will give you (0) coins. |
| Kotlin Heroes 13 Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 338243058 | sunnydev | D | Sept. 12, 2025, 4:28 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 280 | 409600 | ||
| 338228180 | GNU | D | Sept. 12, 2025, 2:57 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 280 | 512000 | ||
| 338240610 | yadavshivam6033 | D | Sept. 12, 2025, 4:12 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 280 | 819200 | ||
| 338231025 | durgeshpatel | D | Sept. 12, 2025, 3:12 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 281 | 0 | ||
| 338244511 | phoenix46 | D | Sept. 12, 2025, 4:39 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 281 | 204800 | ||
| 338247202 | shivendra0305 | D | Sept. 12, 2025, 4:59 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 281 | 819200 | ||
| 338243485 | 216master | D | Sept. 12, 2025, 4:31 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 296 | 0 | ||
| 338230623 | ytm45 | D | Sept. 12, 2025, 3:10 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 296 | 0 | ||
| 338245138 | Nxxlt | D | Sept. 12, 2025, 4:43 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 296 | 204800 | ||
| 338246332 | bhawnapannu27 | D | Sept. 12, 2025, 4:52 p.m. | OK | Kotlin 1.7 | TESTS | 36 | 296 | 614400 | ||
| 338236566 | dpatel_108 | D | Sept. 12, 2025, 3:44 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 171 | 0 | ||
| 338236002 | Intellegent | D | Sept. 12, 2025, 3:41 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 186 | 0 | ||
| 338228217 | __jk__ | D | Sept. 12, 2025, 2:57 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 187 | 0 | ||
| 338226909 | arvindf232 | D | Sept. 12, 2025, 2:50 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 218 | 2355200 | ||
| 338250146 | MohamedAboOkail | D | Sept. 12, 2025, 5:22 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 249 | 13107200 | ||
| 338232289 | MohamedSaeed | D | Sept. 12, 2025, 3:19 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 249 | 13721600 | ||
| 338232057 | errorgorn | D | Sept. 12, 2025, 3:18 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 249 | 15974400 | ||
| 338229045 | inukurthi_srihari | D | Sept. 12, 2025, 3:01 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 312 | 14233600 | ||
| 338242538 | crimsonred | D | Sept. 12, 2025, 4:24 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 312 | 18841600 | ||
| 338234568 | NHiL | D | Sept. 12, 2025, 3:33 p.m. | OK | Kotlin 1.9 | TESTS | 36 | 327 | 0 | ||
| 338235771 | pyromon | D | Sept. 12, 2025, 3:40 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 171 | 0 | ||
| 338227826 | _raaghav_22 | D | Sept. 12, 2025, 2:55 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 186 | 0 | ||
| 338237467 | yossefmesbah95 | D | Sept. 12, 2025, 3:50 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 202 | 0 | ||
| 338249017 | cjtoribio | D | Sept. 12, 2025, 5:13 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 202 | 1228800 | ||
| 338243848 | abhaykumar70953 | D | Sept. 12, 2025, 4:34 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 203 | 921600 | ||
| 338234601 | Iplay1.d4 | D | Sept. 12, 2025, 3:33 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 218 | 0 | ||
| 338234191 | Jlyfish | D | Sept. 12, 2025, 3:31 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 218 | 0 | ||
| 338231720 | __baozii__ | D | Sept. 12, 2025, 3:16 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 218 | 2764800 | ||
| 338240918 | fazliddin2001 | D | Sept. 12, 2025, 4:14 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 233 | 0 | ||
| 338236753 | lto5 | D | Sept. 12, 2025, 3:46 p.m. | OK | Kotlin 2.2 | TESTS | 36 | 234 | 1126400 |
Back to search problems