Submission #84081

#TimeUsernameProblemLanguageResultExecution timeMemory
84081wzyKarte (COCI18_karte)C++11
120 / 120
157 ms7976 KiB
#include <bits/stdc++.h> using namespace std; int n , k; int32_t main(){ scanf("%d%d" , &n , &k); vector<int> big , small; for(int i = 0 ; i < n; i ++){ int x; scanf("%d" , &x); if(x > k) big.push_back(x); else small.push_back(x); } sort(big.begin() , big.end()); sort(small.begin() , small.end()); if(big.size() > k){ puts("-1"); return 0; } else if(big.size() == k){ vector<int> t; for(auto w : big) t.push_back(w); for(auto w : small) t.push_back(w); reverse(t.begin() , t.end()); int fs = 0; for(auto w : t){ if(w <= fs) continue; else fs++; } if(fs == k) for(auto w : t){ printf("%d " , w); } else puts("-1"); } else if(big.size() < k){ int u = k; u-= (int) big.size(); vector<int> pick; int fs = 0; for(auto &w : small){ if(u == 0) break; if(w <= fs){ continue; } else pick.push_back(w) , fs++ , u-- , w = -1; } if(u>0){ puts("-1"); return 0; } for(auto w : big){ pick.push_back(w); } for(auto w : small){ if(w == -1) continue; pick.push_back(w); } fs = 0; bool can = true; for(auto w : pick){ if(w <= fs) continue; else fs++; } if(fs == k){ reverse(pick.begin() , pick.end()); for(auto w : pick) printf("%d " , w ); } else puts("-1"); } }

Compilation message (stderr)

karte.cpp: In function 'int32_t main()':
karte.cpp:17:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(big.size() > k){
     ~~~~~~~~~~~^~~
karte.cpp:21:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  else if(big.size() == k){
          ~~~~~~~~~~~^~~~
karte.cpp:37:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  else if(big.size() < k){
          ~~~~~~~~~~~^~~
karte.cpp:61:8: warning: unused variable 'can' [-Wunused-variable]
   bool can = true;
        ^~~
karte.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d" , &n , &k);
  ~~~~~^~~~~~~~~~~~~~~~~~
karte.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &x);
   ~~~~~^~~~~~~~~~~
#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...
#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...