Submission #367616

#TimeUsernameProblemLanguageResultExecution timeMemory
367616nicolaalexandraGift (IZhO18_nicegift)C++14
100 / 100
1442 ms101328 KiB
#include <bits/stdc++.h> #define DIM 1000010 using namespace std; //set <pair<long long,int> > s; priority_queue <pair<long long,int> > h; vector <pair<long long,int> > w; vector <long long> sol[DIM]; long long v[DIM]; int n,k,i,el; int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>n>>k; long long sum = 0; for (i=1;i<=n;i++){ cin>>v[i]; h.push(make_pair(v[i],i)); sum += v[i]; } if (sum % k){ cout<<-1; return 0; } long long cnt = sum / k; while (!h.empty()){ if (h.size() < k){ cout<<-1; return 0; } int pas = 0; long long val = 0, val2 = 0; w.clear(); for (int i=1;i<=k;i++){ val = h.top().first; int poz = h.top().second; h.pop(); w.push_back(make_pair(val,poz)); } if (!h.empty()) val2 = h.top().first; val = min (val,cnt - val2); sol[++el].push_back (val); cnt -= val; for (auto it : w){ long long x = it.first; int poz = it.second; sol[el].push_back(poz); if (x > val) h.push(make_pair(x-val,poz)); } } cout<<el<<"\n"; for (i=1;i<=el;i++){ for (auto it : sol[i]) cout<<it<<" "; cout<<"\n"; } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:33:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |         if (h.size() < k){
      |             ~~~~~~~~~^~~
nicegift.cpp:38:13: warning: unused variable 'pas' [-Wunused-variable]
   38 |         int pas = 0; long long val = 0, val2 = 0;
      |             ^~~
#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...