# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84901 | 2018-11-17T18:28:45 Z | ToadDaveski | Gift (IZhO18_nicegift) | C++14 | 663 ms | 45660 KB |
#include <bits/stdc++.h> #define ll long long #define fr first #define sc second using namespace std; vector <vector <pair <ll,ll> > > q; ll a[2000001]; map <ll,ll> poz; vector <ll> ans; int main() { ll n,k,i,j,ma=0; cin>>n>>k; ll sum=0,part; for(i=1;i<=n;i++) { cin>>a[i]; sum+=a[i]; ma=max(ma,a[i]); } part=sum/k; if (sum%k || part<ma ) { cout<<-1; return 0; } sum=0; vector <pair <ll,ll> > temp; for(i=1;i<=n;i++) { sum+=a[i]; if (sum>=part) { temp.push_back({a[i]-(sum-part),i}); q.push_back(temp); temp.clear(); sum=sum-part; if (sum) temp.push_back({sum,i}); } else { temp.push_back({a[i],i}); } } while(true) { ll mi=1e9; for(i=0;i<k;i++) mi=min(mi,q[i][poz[i]].fr); ans.push_back(mi); ll kol=0; for(i=0;i<k;i++) { ans.push_back(q[i][poz[i]].sc); q[i][poz[i]].fr-=mi; if (poz[i]<q[i].size() && !q[i][poz[i]].fr) { poz[i]++; if (poz[i]<q[i].size()) kol++; } } if (!kol) break; } ll toad=0; while(toad<ans.size()) { cout<<ans[toad]<<" "; if (((toad+1)%(k+1))==0) cout<<endl; toad++; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 663 ms | 45660 KB | Participant has too long output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |