# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
379233 | jass921026 | Gift (IZhO18_nicegift) | C++14 | 748 ms | 124536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define jizz ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef pair<ll,int> pii;
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mkp make_pair
const int MAXN=1E6+10, MAX_OPS=3E6;
ll A[MAXN];
vector<ll> val;
vector<vector<int> > idx;
vector<int> now;
vector<pii> tmp;
int main(){ jizz
int n, k;
cin>>n>>k;
ll sum=0, mxa=0;
for(int i=1;i<=n;i++){
cin>>A[i];
sum+=A[i];
mxa=max(mxa,A[i]);
}
if(sum%k>0){
cout<<"-1\n";
return 0;
}
if(mxa>sum/k){
cout<<"-1\n";
return 0;
}
ll cur=0;
for(int i=1;i<=n;i++){
if(cur==0) now.pb(i);
cur=cur+A[i];
if(cur>sum/k){
now.pb(i);
cur-=sum/k;
}
tmp.pb(mkp(cur,now.size()-1));
}
sort(ALL(tmp));
ll last=0;
for(int i=0;i<n;i++){
//cout<<"hi "<<tmp[i].F<<" "<<tmp[i].S<<"\n";
if(tmp[i].F!=last){
val.pb(tmp[i].F-last);
idx.pb(now);
}
now[tmp[i].S]++;
last=tmp[i].F;
}
cout<<val.size()<<"\n";
for(int i=0;i<val.size();i++){
cout<<val[i]<<" ";
for(int j=0;j<k;j++){
cout<<idx[i][j]<<" \n"[j==k-1];
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |