#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pr;
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORR(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTR(i,a,b) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define fr first
#define sc second
const int N=2e6+6;
int a[N],indcomp[N];
vector<pair<int,int> > comp[N];
vector<int> ans[N];
int main(){
ios_base::sync_with_stdio(false);
ll n,k;
cin>>n>>k;
ll sum=0;
ll mx=0;
FOR(i,n){
cin>>a[i];
sum+=(ll)a[i];
mx=max(mx,(ll)a[i]);
}
if (sum%k!=0 || sum/k<mx){
cout<<-1<<endl;
return 0;
}
ll tv=0,sahm=sum/k,cnt=0;
FOR(i,n){
if (!a[i])continue;
if (tv+a[i]>=sahm){
comp[cnt].push_back({sahm-tv,i+1});
a[i]-=sahm-tv;
cnt++;
tv=0;
i--;
continue;
}
comp[cnt].push_back({a[i],i+1});
tv+=(ll)a[i];
}
int hert=0;
while(sum){
//cout<<sum<<endl;
int mn=INT_MAX;
FOR(i,k){
mn=min(mn,comp[i][indcomp[i]].fr);
}
ans[hert].push_back(mn);
FOR(i,k){
comp[i][indcomp[i]].fr-=mn;
ans[hert].push_back(comp[i][indcomp[i]].sc);
if (comp[i][indcomp[i]].fr==0)
indcomp[i]++;
}
hert++;
sum-=(k*(ll)mn);
}
cout<<hert<<endl;
FOR(i,hert){
//cout<<ans[i].size()<<" ";
trav(tt,ans[i])cout<<tt<<" ";
cout<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
94328 KB |
n=4 |
2 |
Correct |
72 ms |
94328 KB |
n=3 |
3 |
Correct |
73 ms |
94196 KB |
n=3 |
4 |
Correct |
73 ms |
94200 KB |
n=4 |
5 |
Correct |
73 ms |
94200 KB |
n=4 |
6 |
Correct |
85 ms |
94200 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
94328 KB |
n=4 |
2 |
Correct |
72 ms |
94328 KB |
n=3 |
3 |
Correct |
73 ms |
94196 KB |
n=3 |
4 |
Correct |
73 ms |
94200 KB |
n=4 |
5 |
Correct |
73 ms |
94200 KB |
n=4 |
6 |
Correct |
85 ms |
94200 KB |
n=2 |
7 |
Correct |
84 ms |
94328 KB |
n=5 |
8 |
Correct |
86 ms |
94328 KB |
n=8 |
9 |
Correct |
86 ms |
94200 KB |
n=14 |
10 |
Correct |
76 ms |
94328 KB |
n=11 |
11 |
Correct |
147 ms |
96884 KB |
n=50000 |
12 |
Correct |
153 ms |
96756 KB |
n=50000 |
13 |
Correct |
86 ms |
94200 KB |
n=10 |
14 |
Correct |
76 ms |
94300 KB |
n=685 |
15 |
Correct |
76 ms |
94328 KB |
n=623 |
16 |
Correct |
75 ms |
94332 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
94328 KB |
n=4 |
2 |
Correct |
72 ms |
94328 KB |
n=3 |
3 |
Correct |
73 ms |
94196 KB |
n=3 |
4 |
Correct |
73 ms |
94200 KB |
n=4 |
5 |
Correct |
73 ms |
94200 KB |
n=4 |
6 |
Correct |
85 ms |
94200 KB |
n=2 |
7 |
Correct |
84 ms |
94328 KB |
n=5 |
8 |
Correct |
86 ms |
94328 KB |
n=8 |
9 |
Correct |
86 ms |
94200 KB |
n=14 |
10 |
Correct |
76 ms |
94328 KB |
n=11 |
11 |
Correct |
147 ms |
96884 KB |
n=50000 |
12 |
Correct |
153 ms |
96756 KB |
n=50000 |
13 |
Correct |
86 ms |
94200 KB |
n=10 |
14 |
Correct |
76 ms |
94300 KB |
n=685 |
15 |
Correct |
76 ms |
94328 KB |
n=623 |
16 |
Correct |
75 ms |
94332 KB |
n=973 |
17 |
Correct |
77 ms |
94332 KB |
n=989 |
18 |
Correct |
81 ms |
94408 KB |
n=563 |
19 |
Correct |
76 ms |
94456 KB |
n=592 |
20 |
Correct |
114 ms |
94456 KB |
n=938 |
21 |
Correct |
153 ms |
94328 KB |
n=747 |
22 |
Correct |
77 ms |
94492 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
85 ms |
94400 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
94328 KB |
n=4 |
2 |
Correct |
72 ms |
94328 KB |
n=3 |
3 |
Correct |
73 ms |
94196 KB |
n=3 |
4 |
Correct |
73 ms |
94200 KB |
n=4 |
5 |
Correct |
73 ms |
94200 KB |
n=4 |
6 |
Correct |
85 ms |
94200 KB |
n=2 |
7 |
Correct |
84 ms |
94328 KB |
n=5 |
8 |
Correct |
86 ms |
94328 KB |
n=8 |
9 |
Correct |
86 ms |
94200 KB |
n=14 |
10 |
Correct |
76 ms |
94328 KB |
n=11 |
11 |
Correct |
147 ms |
96884 KB |
n=50000 |
12 |
Correct |
153 ms |
96756 KB |
n=50000 |
13 |
Correct |
86 ms |
94200 KB |
n=10 |
14 |
Correct |
76 ms |
94300 KB |
n=685 |
15 |
Correct |
76 ms |
94328 KB |
n=623 |
16 |
Correct |
75 ms |
94332 KB |
n=973 |
17 |
Correct |
77 ms |
94332 KB |
n=989 |
18 |
Correct |
81 ms |
94408 KB |
n=563 |
19 |
Correct |
76 ms |
94456 KB |
n=592 |
20 |
Correct |
114 ms |
94456 KB |
n=938 |
21 |
Correct |
153 ms |
94328 KB |
n=747 |
22 |
Correct |
77 ms |
94492 KB |
n=991 |
23 |
Incorrect |
85 ms |
94400 KB |
Jury has the answer but participant has not |
24 |
Halted |
0 ms |
0 KB |
- |