# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
486146 | 2021-11-10T15:50:16 Z | luka1234 | Gift (IZhO18_nicegift) | C++14 | 752 ms | 112496 KB |
#include<bits/stdc++.h> #define ll long long #define ff first #define ss second using namespace std; ll n,m; ll a[1000001]; ll sum=0; ll mx=0; int main(){ cin>>n>>m; vector<int> index(n+1,0); vector<vector<pair<ll,ll> > > blocks(n+1); vector<vector<ll> > ans(n+1); for(int k=1;k<=n;k++){ cin>>a[k]; sum+=a[k]; mx=max(mx,a[k]); } if(sum%m!=0||mx>sum/m){ cout<<-1; return 0; } int ind=1; for(int k=1;k<=m;k++){ ll sz=sum/m; while(sz>0){ ll f=a[ind]; if(sz>=f){ sz-=f; ind++; blocks[k].push_back({f,ind}); } else{ a[ind]-=sz; f-=sz; blocks[k].push_back({f,ind}); sz=0; } } } ind=0; while(index[1]<blocks[1].size()){ ll mn=1e18; for(int k=1;k<=m;k++){ mn=min(mn,blocks[k][index[k]].ff); } ans[ind].push_back(mn); for(int k=1;k<=m;k++){ ans[ind].push_back(blocks[k][index[k]].ss); } for(int k=1;k<=m;k++){ blocks[k][index[k]].ff-=mn; if(blocks[k][index[k]].ff==0){ index[k]++; } } ind++; } for(int k=0;k<ind;k++){ for(int i=0;i<ans[k].size();i++){ cout<<ans[k][i]<<' '; } cout<<"\n"; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 204 KB | Taken too much stones from the heap |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 204 KB | Taken too much stones from the heap |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 204 KB | Taken too much stones from the heap |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 752 ms | 112496 KB | Expected int32, but "1000000000000" found |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 204 KB | Taken too much stones from the heap |
2 | Halted | 0 ms | 0 KB | - |