#include <bits/stdc++.h>
#define ll int
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,k,a[200005],s;
set<pair<ll,ll> >st;
vector<vector<ll> >ans;
vector<ll>g;
int main(){
ios::sync_with_stdio(false);
cin >> n >> k;
bool ok = 1;
for(int i=1; i<=n; i++){
cin >> a[i];
if(a[i] != a[1])ok = 0;
s += a[i];
st.insert(mp(-a[i] , i));
}
if(ok){
ll m = n , ind = 1;
while(m - k >= k){
m -= k;
g.clear();
g.pb(a[ind]);
for(int i=ind; i<ind + k; i++){
g.pb(i);
a[i] = 0;
}
ind += k;
ans.pb(g);
}
st.clear();
s = 0;
for(int i=1; i<=n; i++){
s += a[i];
if(a[i])
st.insert(mp(-a[i] , i));
}
}
if(s % k){
cout << "-1";
return 0;
}
ll raod = s / k;
while(raod--){
if((int)st.size() < k){
cout << "-1";
return 0;
}
ll p = 0;
g.clear();
g.pb(1);
for(set<pair<ll,ll> >::iterator it = st.begin(); it != st.end(); it++){
p++;
if(p > k)break;
g.pb((*it).s);
}
for(int i=1; i<g.size(); i++){
st.erase(mp(-a[g[i]] , g[i]));
a[g[i]]--;
if(a[g[i]])st.insert(mp(-a[g[i]] , g[i]));
}
ans.pb(g);
}
cout << (int)ans.size() << endl;
for(int i=0; i<ans.size(); i++){
for(int j=0; j<ans[i].size(); j++)
cout << ans[i][j] << " ";
cout << '\n';
}
return 0;
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:64:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1; i<g.size(); i++){
~^~~~~~~~~
nicegift.cpp:74:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<ans.size(); i++){
~^~~~~~~~~~~
nicegift.cpp:75:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<ans[i].size(); j++)
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
380 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
380 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
5 ms |
1016 KB |
n=8 |
9 |
Correct |
10 ms |
1204 KB |
n=14 |
10 |
Correct |
7 ms |
1016 KB |
n=11 |
11 |
Correct |
48 ms |
5672 KB |
n=50000 |
12 |
Correct |
46 ms |
5672 KB |
n=50000 |
13 |
Correct |
30 ms |
3496 KB |
n=10 |
14 |
Correct |
34 ms |
3120 KB |
n=685 |
15 |
Correct |
36 ms |
3496 KB |
n=623 |
16 |
Correct |
22 ms |
2096 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
380 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
5 ms |
1016 KB |
n=8 |
9 |
Correct |
10 ms |
1204 KB |
n=14 |
10 |
Correct |
7 ms |
1016 KB |
n=11 |
11 |
Correct |
48 ms |
5672 KB |
n=50000 |
12 |
Correct |
46 ms |
5672 KB |
n=50000 |
13 |
Correct |
30 ms |
3496 KB |
n=10 |
14 |
Correct |
34 ms |
3120 KB |
n=685 |
15 |
Correct |
36 ms |
3496 KB |
n=623 |
16 |
Correct |
22 ms |
2096 KB |
n=973 |
17 |
Correct |
35 ms |
2572 KB |
n=989 |
18 |
Correct |
17 ms |
1016 KB |
n=563 |
19 |
Correct |
27 ms |
1384 KB |
n=592 |
20 |
Correct |
27 ms |
1376 KB |
n=938 |
21 |
Correct |
22 ms |
1272 KB |
n=747 |
22 |
Correct |
24 ms |
1272 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
70 ms |
20004 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
380 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
5 ms |
1016 KB |
n=8 |
9 |
Correct |
10 ms |
1204 KB |
n=14 |
10 |
Correct |
7 ms |
1016 KB |
n=11 |
11 |
Correct |
48 ms |
5672 KB |
n=50000 |
12 |
Correct |
46 ms |
5672 KB |
n=50000 |
13 |
Correct |
30 ms |
3496 KB |
n=10 |
14 |
Correct |
34 ms |
3120 KB |
n=685 |
15 |
Correct |
36 ms |
3496 KB |
n=623 |
16 |
Correct |
22 ms |
2096 KB |
n=973 |
17 |
Correct |
35 ms |
2572 KB |
n=989 |
18 |
Correct |
17 ms |
1016 KB |
n=563 |
19 |
Correct |
27 ms |
1384 KB |
n=592 |
20 |
Correct |
27 ms |
1376 KB |
n=938 |
21 |
Correct |
22 ms |
1272 KB |
n=747 |
22 |
Correct |
24 ms |
1272 KB |
n=991 |
23 |
Runtime error |
70 ms |
20004 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
24 |
Halted |
0 ms |
0 KB |
- |