Submission #787620

#TimeUsernameProblemLanguageResultExecution timeMemory
787620willychanGift (IZhO18_nicegift)C++14
30 / 100
28 ms4172 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; //#include<bits/extc++.h> //__gnu_pbds int main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n,k;cin>>n>>k; ll sum=0; vector<int> arr(n); int maxn = 0; for(int i=0;i<n;i++){ cin>>arr[i]; sum+=arr[i]; maxn = max(maxn,arr[i]); } if(sum%k){ cout<<-1<<"\n"; return 0; } if(maxn>sum/k){ cout<<-1<<"\n"; return 0; } priority_queue<pair<int,int> > pq; for(int i=0;i<n;i++){ pq.push({arr[i],i}); } vector<vector<int>> ans; while(pq.size()>=k){ vector<int> v(k); ll tomi = LONG_LONG_MAX; for(int i=0;i<k;i++){ v[i] = pq.top().second; tomi = pq.top().first; pq.pop(); } if(pq.size()) tomi = min(tomi,(sum/k)-pq.top().first); sum-=k*tomi; vector<int> tempans; tempans.push_back(tomi); for(auto i : v){ tempans.push_back(i+1); arr[i]-=tomi; if(arr[i]) pq.push({arr[i],i}); } ans.push_back(tempans); } cout<<ans.size()<<"\n"; for(auto ar : ans){ for(auto v : ar){ cout<<v<<" "; } cout<<"\n"; } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:34:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |  while(pq.size()>=k){
      |        ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...