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 |
|---|---|---|---|---|---|---|
| 2183 | Hello 2026 | FINISHED | False | 10800 | 8609123 | Jan. 7, 2026, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 158 ) | H | Minimise Cost | PROGRAMMING | dp |
For any sequence (b) of length (m), we define its cost function (f(b)) as: () f(b) = m \cdot \sum_{i=1}^m b_i.() You are given a sequence (a) of length (n) and an integer (k). Your task is to partition the sequence (a) into exactly (k) non-empty subsequences (^{\text{∗}}), denoted as (s_1, s_2, \ldots, s_k). Every element of the original sequence (a) must belong to exactly one of these subsequences. Find the minimum possible value of the total cost: () \sum_{i=1}^k f(s_i).() (^{\text{∗}})A sequence (c) is a subsequence of a sequence (d) if (c) can be obtained from (d) by the deletion of several (possibly, zero or all) element from arbitrary positions. 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 k\le n \le 2\cdot 10^5)) — the length of the sequence and the number of subsequences required. The second line contains (n) integers (a_1, a_2, \ldots, a_n) ((\mathbf{-10^9} \le a_i \le \mathbf{10^9})) — the elements of the sequence (a). It is guaranteed that the sum of (n) across all test cases does not exceed (2\cdot 10^5). For each test case, output a single integer – the minimum sum of cost over all subsequences. In the first test case, it is optimal to split into (1,-2) and (3). The total score is (2(1-2)+1(3)=1). In the second test case, the only possible way to partition is with (1) subsequence (1,3,-2). The score is (3(1+3-2)=6). |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 356877220 | RDDCCD | H | Jan. 7, 2026, 7:47 p.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 875 | 7270400 | ||
| 356895823 | qiuzx | H | Jan. 8, 2026, 3:17 a.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 1265 | 10444800 | ||
| 356894579 | LMydd0225 | H | Jan. 8, 2026, 2:56 a.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 1625 | 41779200 | ||
| 356902334 | liaoz123 | H | Jan. 8, 2026, 4:55 a.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 2171 | 64204800 | ||
| 356885683 | wrihapcod | H | Jan. 7, 2026, 10:30 p.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 5968 | 32153600 | ||
| 356857586 | ecnerwala | H | Jan. 7, 2026, 5:09 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 984 | 14643200 | ||
| 356904991 | khushicodes03 | H | Jan. 8, 2026, 5:26 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 1343 | 45363200 | ||
| 356890557 | Legend_of_Bangladesh | H | Jan. 8, 2026, 1:30 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 1546 | 45260800 | ||
| 356886553 | NhatHuy08052015 | H | Jan. 7, 2026, 10:59 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 1546 | 45260800 | ||
| 356908718 | larsr | H | Jan. 8, 2026, 6:08 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 2109 | 14438400 | ||
| 356882939 | ttamx | H | Jan. 7, 2026, 9:19 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 2171 | 14131200 | ||
| 356889806 | cuteSubtask | H | Jan. 8, 2026, 1:04 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 2562 | 450662400 | ||
| 356877679 | turmax | H | Jan. 7, 2026, 7:53 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 2796 | 33075200 | ||
| 356876702 | yorisou | H | Jan. 7, 2026, 7:40 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 2812 | 6041600 | ||
| 356879142 | turmax | H | Jan. 7, 2026, 8:15 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 62 | 2828 | 33075200 |
Back to search problems