Submission #367408

#TimeUsernameProblemLanguageResultExecution timeMemory
367408nicolaalexandraGift (IZhO18_nicegift)C++14
0 / 100
551 ms70956 KiB
#include <bits/stdc++.h> #define DIM 1000010 using namespace std; set <pair<int,int> > s; vector <pair<int,int> > w; vector <int> sol[DIM]; int v[DIM]; int n,k,i,el; int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>n>>k; for (i=1;i<=n;i++){ cin>>v[i]; s.insert(make_pair(v[i],i)); } while (!s.empty()){ if (s.size() < k){ cout<<-1; return 0; } int val = s.begin()->first; sol[++el].push_back (val); int pas = 0; w.clear(); for (auto it : s){ w.push_back(it); sol[el].push_back(it.second); pas++; if (pas == k) break; } for (auto it : w){ int x = it.first, poz = it.second; 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:23:22: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |         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...