#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
#define int ll
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,k;cin>>n>>k;
ll sum=0;
vector<int> arr(n);
priority_queue<pair<int,int> > pq;
for(int i=0;i<n;i++){
cin>>arr[i];
sum+=arr[i];
pq.push({arr[i],i});
}
if(sum%k){
cout<<-1<<"\n";
return 0;
}
if(pq.top().first>sum/k){
cout<<-1<<"\n";
return 0;
}
vector<vector<int>> ans;
while(sum){
vector<int> v;
ll tomi = LONG_LONG_MAX;
for(int i=0;i<k;i++){
v.push_back(pq.top().second);
tomi = pq.top().first;
pq.pop();
}
if(pq.size()) tomi = min(tomi,(sum/k)-pq.top().first);
sum-=k*tomi;
vector<int> tempans;
tempans.push_back(tomi);
for(auto i : v){
tempans.push_back(i+1);
arr[i]-=tomi;
if(arr[i]) pq.push({arr[i],i});
}
ans.push_back(tempans);
}
cout<<ans.size()<<"\n";
for(auto ar : ans){
for(auto v : ar){
cout<<v<<" ";
}
cout<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
19 ms |
3536 KB |
n=50000 |
12 |
Correct |
16 ms |
3280 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 |
1 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 |
19 ms |
3536 KB |
n=50000 |
12 |
Correct |
16 ms |
3280 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 |
420 ms |
65732 KB |
n=1000000 |
2 |
Correct |
255 ms |
48672 KB |
n=666666 |
3 |
Correct |
146 ms |
26700 KB |
n=400000 |
4 |
Correct |
96 ms |
17760 KB |
n=285714 |
5 |
Correct |
6 ms |
1368 KB |
n=20000 |
6 |
Correct |
65 ms |
11140 KB |
n=181818 |
7 |
Correct |
3 ms |
852 KB |
n=10000 |
8 |
Correct |
3 ms |
724 KB |
n=6666 |
9 |
Correct |
2 ms |
468 KB |
n=4000 |
10 |
Correct |
3 ms |
660 KB |
n=2857 |
11 |
Correct |
1 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 |
1 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 |
19 ms |
3536 KB |
n=50000 |
12 |
Correct |
16 ms |
3280 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 |
420 ms |
65732 KB |
n=1000000 |
24 |
Correct |
255 ms |
48672 KB |
n=666666 |
25 |
Correct |
146 ms |
26700 KB |
n=400000 |
26 |
Correct |
96 ms |
17760 KB |
n=285714 |
27 |
Correct |
6 ms |
1368 KB |
n=20000 |
28 |
Correct |
65 ms |
11140 KB |
n=181818 |
29 |
Correct |
3 ms |
852 KB |
n=10000 |
30 |
Correct |
3 ms |
724 KB |
n=6666 |
31 |
Correct |
2 ms |
468 KB |
n=4000 |
32 |
Correct |
3 ms |
660 KB |
n=2857 |
33 |
Correct |
1 ms |
340 KB |
n=2000 |
34 |
Correct |
13 ms |
2260 KB |
n=23514 |
35 |
Correct |
13 ms |
2248 KB |
n=23514 |
36 |
Correct |
1 ms |
340 KB |
n=940 |
37 |
Correct |
0 ms |
212 KB |
n=2 |
38 |
Correct |
34 ms |
5628 KB |
n=100000 |
39 |
Correct |
33 ms |
5560 KB |
n=100000 |
40 |
Correct |
1 ms |
212 KB |
n=10 |
41 |
Correct |
1 ms |
340 KB |
n=100 |
42 |
Correct |
2 ms |
468 KB |
n=1000 |
43 |
Correct |
506 ms |
86768 KB |
n=1000000 |
44 |
Correct |
783 ms |
96572 KB |
n=1000000 |
45 |
Correct |
480 ms |
63676 KB |
n=666666 |
46 |
Correct |
261 ms |
36044 KB |
n=400000 |
47 |
Correct |
8 ms |
1100 KB |
n=2336 |
48 |
Correct |
484 ms |
54712 KB |
n=285714 |
49 |
Correct |
418 ms |
45352 KB |
n=181818 |
50 |
Correct |
21 ms |
3024 KB |
n=40000 |
51 |
Correct |
10 ms |
1620 KB |
n=20000 |
52 |
Correct |
7 ms |
976 KB |
n=10000 |
53 |
Correct |
43 ms |
4376 KB |
n=6666 |
54 |
Correct |
5 ms |
692 KB |
n=4000 |
55 |
Correct |
163 ms |
16184 KB |
n=2857 |
56 |
Correct |
2 ms |
468 KB |
n=2000 |