# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84081 | wzy | Karte (COCI18_karte) | C++11 | 157 ms | 7976 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |