#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();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
312 KB |
n=3 |
4 |
Correct |
1 ms |
308 KB |
n=4 |
5 |
Correct |
0 ms |
312 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
312 KB |
n=3 |
4 |
Correct |
1 ms |
308 KB |
n=4 |
5 |
Correct |
0 ms |
312 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
308 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Runtime error |
1671 ms |
524288 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
312 KB |
n=3 |
4 |
Correct |
1 ms |
308 KB |
n=4 |
5 |
Correct |
0 ms |
312 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
308 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Runtime error |
1671 ms |
524288 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
828 ms |
87080 KB |
n=1000000 |
2 |
Correct |
578 ms |
48616 KB |
n=666666 |
3 |
Correct |
316 ms |
27676 KB |
n=400000 |
4 |
Execution timed out |
2094 ms |
273584 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
312 KB |
n=3 |
4 |
Correct |
1 ms |
308 KB |
n=4 |
5 |
Correct |
0 ms |
312 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
308 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Runtime error |
1671 ms |
524288 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |