#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
using ll = long long;
using pii = pair <int, int>;
#define pb push_back
const int maxN = 1e6 + 10;
const int maxOP = 3e6;
int n, k;
int a[maxN];
priority_queue <pii> PQ;
vector <vector <int>> e;
void Init(){
cin >> n >> k;
ll sum = 0;
for (int i = 1; i <= n; ++i){
cin >> a[i];
sum += a[i];
PQ.push({a[i], i});
}
if (sum % k || PQ.top().fi > sum / k){
cout << -1; return;
}
while (sum){
vector <int> pos;
for (int j = 0; j < k; ++j){
pos.pb(PQ.top().se);
PQ.pop();
}
int add = a[pos.back()];
if (!PQ.empty()) add = min(add, sum / k - PQ.top().fi);
sum -= add * k;
e.pb({add});
for (int j = 0; j < k; ++j){
e.back().pb(pos[j]);
a[pos[j]] -= add;
PQ.push({a[pos[j]], pos[j]});
}
}
cout << e.size() << "\n";
for (auto &i: e){
for (auto &j: i) cout << j << " ";
cout << "\n";
}
}
signed main() {
Init();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
212 KB |
n=4 |
5 |
Correct |
0 ms |
212 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
212 KB |
n=4 |
5 |
Correct |
0 ms |
212 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
212 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
212 KB |
n=14 |
10 |
Correct |
0 ms |
212 KB |
n=11 |
11 |
Correct |
30 ms |
3936 KB |
n=50000 |
12 |
Correct |
23 ms |
3528 KB |
n=50000 |
13 |
Correct |
0 ms |
212 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
212 KB |
n=4 |
5 |
Correct |
0 ms |
212 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
212 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
212 KB |
n=14 |
10 |
Correct |
0 ms |
212 KB |
n=11 |
11 |
Correct |
30 ms |
3936 KB |
n=50000 |
12 |
Correct |
23 ms |
3528 KB |
n=50000 |
13 |
Correct |
0 ms |
212 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
1 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
340 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
811 ms |
73476 KB |
n=1000000 |
2 |
Correct |
545 ms |
39424 KB |
n=666666 |
3 |
Correct |
304 ms |
22076 KB |
n=400000 |
4 |
Correct |
207 ms |
13700 KB |
n=285714 |
5 |
Correct |
14 ms |
1096 KB |
n=20000 |
6 |
Correct |
132 ms |
9216 KB |
n=181818 |
7 |
Correct |
7 ms |
724 KB |
n=10000 |
8 |
Correct |
6 ms |
572 KB |
n=6666 |
9 |
Correct |
3 ms |
468 KB |
n=4000 |
10 |
Correct |
5 ms |
596 KB |
n=2857 |
11 |
Correct |
2 ms |
340 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
212 KB |
n=4 |
5 |
Correct |
0 ms |
212 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
212 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
212 KB |
n=14 |
10 |
Correct |
0 ms |
212 KB |
n=11 |
11 |
Correct |
30 ms |
3936 KB |
n=50000 |
12 |
Correct |
23 ms |
3528 KB |
n=50000 |
13 |
Correct |
0 ms |
212 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
1 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
340 KB |
n=991 |
23 |
Correct |
811 ms |
73476 KB |
n=1000000 |
24 |
Correct |
545 ms |
39424 KB |
n=666666 |
25 |
Correct |
304 ms |
22076 KB |
n=400000 |
26 |
Correct |
207 ms |
13700 KB |
n=285714 |
27 |
Correct |
14 ms |
1096 KB |
n=20000 |
28 |
Correct |
132 ms |
9216 KB |
n=181818 |
29 |
Correct |
7 ms |
724 KB |
n=10000 |
30 |
Correct |
6 ms |
572 KB |
n=6666 |
31 |
Correct |
3 ms |
468 KB |
n=4000 |
32 |
Correct |
5 ms |
596 KB |
n=2857 |
33 |
Correct |
2 ms |
340 KB |
n=2000 |
34 |
Correct |
18 ms |
2320 KB |
n=23514 |
35 |
Correct |
20 ms |
2404 KB |
n=23514 |
36 |
Correct |
1 ms |
340 KB |
n=940 |
37 |
Correct |
0 ms |
212 KB |
n=2 |
38 |
Correct |
53 ms |
5820 KB |
n=100000 |
39 |
Correct |
62 ms |
5764 KB |
n=100000 |
40 |
Correct |
0 ms |
212 KB |
n=10 |
41 |
Correct |
1 ms |
312 KB |
n=100 |
42 |
Correct |
3 ms |
468 KB |
n=1000 |
43 |
Correct |
937 ms |
98492 KB |
n=1000000 |
44 |
Correct |
1327 ms |
108240 KB |
n=1000000 |
45 |
Correct |
934 ms |
63764 KB |
n=666666 |
46 |
Correct |
490 ms |
38096 KB |
n=400000 |
47 |
Correct |
10 ms |
1108 KB |
n=2336 |
48 |
Correct |
650 ms |
54636 KB |
n=285714 |
49 |
Correct |
568 ms |
50820 KB |
n=181818 |
50 |
Correct |
53 ms |
3120 KB |
n=40000 |
51 |
Correct |
22 ms |
1600 KB |
n=20000 |
52 |
Correct |
12 ms |
1104 KB |
n=10000 |
53 |
Correct |
49 ms |
5936 KB |
n=6666 |
54 |
Correct |
6 ms |
616 KB |
n=4000 |
55 |
Correct |
189 ms |
20864 KB |
n=2857 |
56 |
Correct |
4 ms |
452 KB |
n=2000 |