Kotlin Heroes: Episode 4

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
1346 Kotlin Heroes: Episode 4 FINISHED False 9000 141060299 May 29, 2020, 2:35 p.m.

Problems

Solved$
Index
Name
Type
Tags
Community Tag
Rating
( 608 ) C Spring Cleaning PROGRAMMING *special greedy sortings 1600

B"Tanya wants to organize her bookcase. There are n bookshelves in the bookcase, the i -th bookshelf contains a_i books on it. Tanya will be satisfied if each bookshelf contains no more than k books. Tanya can do one of the two following operations to achieve her goal: Consider the sequence a of n integers. Then its even distribution is such a sequence b of n integers that the sum of b equals the sum of a and the value max(b) - min(b) is the minimum possible. For example, if the array a=[5, 4, 3] then its even distribution is b=[4, 4, 4] . If a=[1, 2, 3, 4] then its even distribution is b=[2, 3, 3, 2] (or any permutation of this array). Your task is to find the minimum number of seconds Tanya has to spend to obtain the bookcase with no more than k books on each bookshelf. The first line of the input contains one integer t ( 1 <= t <= 10^4 ) -- the number of test cases. Then t test cases follow. The first line of the test case contains four integers n, k, x and y ( 1 <= k <= n <= 2 cdot 10^5; 1 <= x, y <= 10^4 ) -- the number of bookshelves, the maximum required number of books on each bookshelf and the number of seconds Tanya spends during the first and the second operation respectively. The second line of the test case contains n integers a_1, a_2, ... , a_n ( 1 <= a_i <= n ), where a_i is the number of books on the i -th bookshelf. It is guaranteed that the sum of n over all test cases does not exceed 2 cdot 10^5 ( sum n <= 2 cdot 10^5 ). For each test case, print the answer -- the minimum number of seconds Tanya has to spend to obtain the bookcase with no more than k books on each bookshelf. In the first test case of the example, it's optimal to use the first operation on the fifth bookshelf. So the array a becomes [1, 2, 2, 3, 5] rightarrow [1, 2, 2, "...

Tutorials

Kotlin Heroes: Episode 4 — Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
81901936 Egor C May 29, 2020, 3:23 p.m. OK Kotlin TESTS 18 124 0 1600
81897688 timf1089 C May 29, 2020, 2:53 p.m. OK Kotlin TESTS 18 156 3379200 1600
81898129 Omar_Tarek C May 29, 2020, 2:56 p.m. OK Kotlin TESTS 18 170 3379200 1600
81899476 icebound C May 29, 2020, 3:05 p.m. OK Kotlin TESTS 18 171 0 1600
81896867 eatmore C May 29, 2020, 2:48 p.m. OK Kotlin TESTS 18 171 2969600 1600
81900410 Spheniscine C May 29, 2020, 3:11 p.m. OK Kotlin TESTS 18 187 1126400 1600
81907545 CryMeANile C May 29, 2020, 4:07 p.m. OK Kotlin TESTS 18 187 1740800 1600
81898664 6aren C May 29, 2020, 2:59 p.m. OK Kotlin TESTS 18 187 3379200 1600
81896942 galen_colin C May 29, 2020, 2:48 p.m. OK Kotlin TESTS 18 187 4403200 1600
81899270 artsin666 C May 29, 2020, 3:03 p.m. OK Kotlin TESTS 18 187 5120000 1600

remove filters

Back to search problems