# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338244 | 2020-12-22T20:00:02 Z | Kerim | Gift (IZhO18_nicegift) | C++17 | 486 ms | 75616 KB |
#include "bits/stdc++.h" #define MAXN 1000009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} ll arr[MAXN]; vector<pair<ll,int> >adj[MAXN]; const ll B=2e18; int main(){ // freopen("file.in", "r", stdin); int n,k,tmp=0; scanf("%d%d",&n,&k); ll sum=0,mx=0,cur=0; for(int i=1;i<=n;i++) scanf("%lld",arr+i),sum+=arr[i],umax(mx,arr[i]); if(sum%k!=0 or mx>sum/k) return printf("-1\n")*0; for(int i=1;i<=n;i++){ cur+=arr[i]; if(cur>=sum/k){ adj[tmp++].pb(mp(sum/k-cur+arr[i],i)); if(cur>sum/k) adj[tmp].pb(mp(cur-sum/k,i)); cur=0; } else adj[tmp].pb(mp(arr[i],i)); }assert(tmp==k); for(int i=0;i<k;i++) reverse(all(adj[i])); while(!adj[0].empty()){ ll mn=B; for(int i=0;i<k;i++) umin(mn,adj[i].back().ff); printf("%lld ",mn); for(int i=0;i<k;i++){ printf("%d ",adj[i].back().ss); if(adj[i].back().ff==mn) adj[i].ppb(); else adj[i].back().ff-=mn; }puts(""); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 23788 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 23788 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 23788 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 486 ms | 75616 KB | Expected int32, but "1000000000000" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 23788 KB | Not all heaps are empty in the end |
2 | Halted | 0 ms | 0 KB | - |