Submission #367612

#TimeUsernameProblemLanguageResultExecution timeMemory
367612nicolaalexandraGift (IZhO18_nicegift)C++14
49 / 100
2039 ms116292 KiB
#include <bits/stdc++.h> #define DIM 1000010 using namespace std; set <pair<long long,int> > s; 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]; s.insert(make_pair(v[i],i)); sum += v[i]; } if (sum % k){ cout<<-1; return 0; } long long cnt = sum / k; while (!s.empty()){ if (s.size() < k){ cout<<-1; return 0; } int pas = 0; long long val = 0, val2 = 0; w.clear(); for (set <pair<long long,int> > :: reverse_iterator it = s.rbegin(); it != s.rend(); it++){ //sol[el].push_back(it->second); pas++; if (pas == k+1){ val2 = it->first; break; } w.push_back(make_pair(it->first,it->second)); val = it->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); s.erase(make_pair(x,poz)); if (x > val) s.insert(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:32:22: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         if (s.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...