#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<long long> A(N);
priority_queue<pair<long long, int>> Q;
long long sum = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
Q.push({A[i], i});
sum += A[i];
}
vector<vector<long long>> answer;
vector<int> pos;
int cnt = 0;
while ((int)Q.size() >= K) {
pos.clear();
long long val = numeric_limits<long long>::max();
for (int i = 0; i < K; i++) {
val = min(val, Q.top().first);
pos.push_back(Q.top().second);
Q.pop();
}
if (!Q.empty()) {
val = min(val, sum / K - Q.top().first);
}
answer.push_back({val});
for (int i : pos) {
answer.back().push_back(1 + i);
if ((A[i] -= val) > 0) {
Q.push({A[i], i});
}
sum -= val;
}
cnt += K;
}
if (Q.empty()) {
cout << answer.size() << "\n";
for (auto &op : answer) {
for (int i = 0; i <= K; i++) {
cout << op[i] << " \n"[i == K];
}
}
} else {
cout << "-1\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
1 ms |
348 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
1 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
0 ms |
348 KB |
n=14 |
10 |
Correct |
1 ms |
348 KB |
n=11 |
11 |
Correct |
15 ms |
4056 KB |
n=50000 |
12 |
Correct |
13 ms |
3544 KB |
n=50000 |
13 |
Correct |
0 ms |
348 KB |
n=10 |
14 |
Correct |
1 ms |
348 KB |
n=685 |
15 |
Correct |
1 ms |
348 KB |
n=623 |
16 |
Correct |
1 ms |
348 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
1 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
0 ms |
348 KB |
n=14 |
10 |
Correct |
1 ms |
348 KB |
n=11 |
11 |
Correct |
15 ms |
4056 KB |
n=50000 |
12 |
Correct |
13 ms |
3544 KB |
n=50000 |
13 |
Correct |
0 ms |
348 KB |
n=10 |
14 |
Correct |
1 ms |
348 KB |
n=685 |
15 |
Correct |
1 ms |
348 KB |
n=623 |
16 |
Correct |
1 ms |
348 KB |
n=973 |
17 |
Correct |
1 ms |
348 KB |
n=989 |
18 |
Correct |
0 ms |
348 KB |
n=563 |
19 |
Correct |
1 ms |
348 KB |
n=592 |
20 |
Correct |
1 ms |
348 KB |
n=938 |
21 |
Correct |
1 ms |
348 KB |
n=747 |
22 |
Correct |
0 ms |
348 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
73136 KB |
n=1000000 |
2 |
Correct |
188 ms |
51128 KB |
n=666666 |
3 |
Correct |
109 ms |
28604 KB |
n=400000 |
4 |
Correct |
79 ms |
18488 KB |
n=285714 |
5 |
Correct |
5 ms |
1504 KB |
n=20000 |
6 |
Correct |
46 ms |
11728 KB |
n=181818 |
7 |
Correct |
3 ms |
984 KB |
n=10000 |
8 |
Correct |
2 ms |
904 KB |
n=6666 |
9 |
Correct |
2 ms |
604 KB |
n=4000 |
10 |
Correct |
3 ms |
860 KB |
n=2857 |
11 |
Correct |
1 ms |
348 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
1 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
0 ms |
348 KB |
n=14 |
10 |
Correct |
1 ms |
348 KB |
n=11 |
11 |
Correct |
15 ms |
4056 KB |
n=50000 |
12 |
Correct |
13 ms |
3544 KB |
n=50000 |
13 |
Correct |
0 ms |
348 KB |
n=10 |
14 |
Correct |
1 ms |
348 KB |
n=685 |
15 |
Correct |
1 ms |
348 KB |
n=623 |
16 |
Correct |
1 ms |
348 KB |
n=973 |
17 |
Correct |
1 ms |
348 KB |
n=989 |
18 |
Correct |
0 ms |
348 KB |
n=563 |
19 |
Correct |
1 ms |
348 KB |
n=592 |
20 |
Correct |
1 ms |
348 KB |
n=938 |
21 |
Correct |
1 ms |
348 KB |
n=747 |
22 |
Correct |
0 ms |
348 KB |
n=991 |
23 |
Correct |
301 ms |
73136 KB |
n=1000000 |
24 |
Correct |
188 ms |
51128 KB |
n=666666 |
25 |
Correct |
109 ms |
28604 KB |
n=400000 |
26 |
Correct |
79 ms |
18488 KB |
n=285714 |
27 |
Correct |
5 ms |
1504 KB |
n=20000 |
28 |
Correct |
46 ms |
11728 KB |
n=181818 |
29 |
Correct |
3 ms |
984 KB |
n=10000 |
30 |
Correct |
2 ms |
904 KB |
n=6666 |
31 |
Correct |
2 ms |
604 KB |
n=4000 |
32 |
Correct |
3 ms |
860 KB |
n=2857 |
33 |
Correct |
1 ms |
348 KB |
n=2000 |
34 |
Correct |
10 ms |
2648 KB |
n=23514 |
35 |
Correct |
10 ms |
2648 KB |
n=23514 |
36 |
Correct |
1 ms |
348 KB |
n=940 |
37 |
Correct |
0 ms |
348 KB |
n=2 |
38 |
Correct |
28 ms |
6004 KB |
n=100000 |
39 |
Correct |
29 ms |
5844 KB |
n=100000 |
40 |
Correct |
0 ms |
348 KB |
n=10 |
41 |
Correct |
0 ms |
460 KB |
n=100 |
42 |
Correct |
2 ms |
604 KB |
n=1000 |
43 |
Correct |
359 ms |
99616 KB |
n=1000000 |
44 |
Correct |
561 ms |
109484 KB |
n=1000000 |
45 |
Correct |
356 ms |
63668 KB |
n=666666 |
46 |
Correct |
221 ms |
40304 KB |
n=400000 |
47 |
Correct |
9 ms |
1372 KB |
n=2336 |
48 |
Correct |
379 ms |
56728 KB |
n=285714 |
49 |
Correct |
336 ms |
52504 KB |
n=181818 |
50 |
Correct |
18 ms |
3292 KB |
n=40000 |
51 |
Correct |
9 ms |
1756 KB |
n=20000 |
52 |
Correct |
6 ms |
1240 KB |
n=10000 |
53 |
Correct |
38 ms |
5972 KB |
n=6666 |
54 |
Correct |
3 ms |
604 KB |
n=4000 |
55 |
Correct |
158 ms |
20820 KB |
n=2857 |
56 |
Correct |
2 ms |
604 KB |
n=2000 |