#include<bits/stdc++.h>
using namespace std;
const int N = (int)1e6+7;
int n, k;
long long a[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
long long tot = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
tot += a[i];
}
set<pair<long long, int> > s;
for(int i = 1; i <= n; ++i) {
s.insert({a[i], i});
}
vector<vector<long long> > ans;
while((int)s.size()>=k) {
vector<int> cur;
for(int j = 0; j < k; ++j) {
auto it = --s.end();
cur.push_back(it->second);
s.erase(it);
}
int can = 1;
if(!s.empty()) {
can = (--s.end())->first;
}
can = a[cur.back()]-can+1;
vector<long long> v={can};
for(auto id : cur) {
assert(a[id]>=can);
v.push_back(id);
}
ans.push_back(v);
for(auto id : cur) {
a[id] -= can;
if(a[id]>0) {
s.insert({a[id], id});
}
}
}
if(!s.empty()) {
cout << "-1\n";
return 0;
}
cout << (int)ans.size() << "\n";
for(auto x : ans) {
for(auto y : x) {
cout << y << ' ';
}
cout << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
1 ms |
348 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
1 ms |
348 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
344 KB |
n=5 |
8 |
Correct |
1 ms |
344 KB |
n=8 |
9 |
Correct |
5 ms |
1116 KB |
n=14 |
10 |
Correct |
3 ms |
840 KB |
n=11 |
11 |
Correct |
24 ms |
7188 KB |
n=50000 |
12 |
Correct |
29 ms |
7952 KB |
n=50000 |
13 |
Correct |
12 ms |
1812 KB |
n=10 |
14 |
Correct |
29 ms |
3112 KB |
n=685 |
15 |
Correct |
25 ms |
3344 KB |
n=623 |
16 |
Correct |
15 ms |
1964 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
1 ms |
348 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
344 KB |
n=5 |
8 |
Correct |
1 ms |
344 KB |
n=8 |
9 |
Correct |
5 ms |
1116 KB |
n=14 |
10 |
Correct |
3 ms |
840 KB |
n=11 |
11 |
Correct |
24 ms |
7188 KB |
n=50000 |
12 |
Correct |
29 ms |
7952 KB |
n=50000 |
13 |
Correct |
12 ms |
1812 KB |
n=10 |
14 |
Correct |
29 ms |
3112 KB |
n=685 |
15 |
Correct |
25 ms |
3344 KB |
n=623 |
16 |
Correct |
15 ms |
1964 KB |
n=973 |
17 |
Correct |
30 ms |
3308 KB |
n=989 |
18 |
Correct |
10 ms |
1360 KB |
n=563 |
19 |
Correct |
16 ms |
1884 KB |
n=592 |
20 |
Correct |
19 ms |
1884 KB |
n=938 |
21 |
Correct |
12 ms |
1372 KB |
n=747 |
22 |
Correct |
14 ms |
1628 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2048 ms |
235348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
1 ms |
348 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
344 KB |
n=5 |
8 |
Correct |
1 ms |
344 KB |
n=8 |
9 |
Correct |
5 ms |
1116 KB |
n=14 |
10 |
Correct |
3 ms |
840 KB |
n=11 |
11 |
Correct |
24 ms |
7188 KB |
n=50000 |
12 |
Correct |
29 ms |
7952 KB |
n=50000 |
13 |
Correct |
12 ms |
1812 KB |
n=10 |
14 |
Correct |
29 ms |
3112 KB |
n=685 |
15 |
Correct |
25 ms |
3344 KB |
n=623 |
16 |
Correct |
15 ms |
1964 KB |
n=973 |
17 |
Correct |
30 ms |
3308 KB |
n=989 |
18 |
Correct |
10 ms |
1360 KB |
n=563 |
19 |
Correct |
16 ms |
1884 KB |
n=592 |
20 |
Correct |
19 ms |
1884 KB |
n=938 |
21 |
Correct |
12 ms |
1372 KB |
n=747 |
22 |
Correct |
14 ms |
1628 KB |
n=991 |
23 |
Execution timed out |
2048 ms |
235348 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |