#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int, int>
#define ft first
#define sd second
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
const int oo = 2e9;
const ll OO = 1e18;
const int N = 100100;
set<pii, greater<pii> > st;
vector<vector<int> > ans;
vector<int> vc;
int n, k, a[N], sm;
void BAD(){
cout << -1;
exit(0);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; i++){
cin >> a[i];
sm += a[i];
st.insert(MP(a[i], i));
}
while (sm > 0){
vc.clear();
for (int it = 0; it < k; it++){
pii cr = (*st.begin());
st.erase(st.begin());
if (cr.ft == 0)
BAD();
a[cr.sd]--;
sm--;
vc.PB(cr.sd);
}
ans.PB(vc);
for (int x : vc)
st.insert(MP(a[x], x));
}
cout << sz(ans) << '\n';
for (int it = 0; it < sz(ans); it++){
for (int x : ans[it])
cout << x + 1 << " ";
cout << "1\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
41 ms |
10488 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Taken too much stones from the heap |
2 |
Halted |
0 ms |
0 KB |
- |