# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
486754 |
2021-11-12T17:18:38 Z |
perchuts |
Karte (COCI18_karte) |
C++17 |
|
119 ms |
6556 KB |
#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf (int)(2e9+1)
#define mod (int)(1e9+7)
using namespace std;
int v[5*maxn],ans[5*maxn];
set<int>cards;
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,k,cnt=0;
cin>>n>>k;
for(int i=1;i<=n;i++){
int x;
cin>>x;
v[x]++;
cards.insert(x);
if(x>k)cnt++;
}
if(cnt>k){
cout<<"-1"<<endl;
return 0;
}
for(int i=0;i<k;i++){
if(k-i-1<cnt){
set<int>::iterator it2=cards.lower_bound(k+1);
if(it2==cards.end()){
cout<<"-1"<<endl;
return 0;
}
v[*it2]--;
ans[i]=*it2;
if(v[*it2]==0){
cards.erase(*it2);
}
}else{
set<int>::iterator it=cards.lower_bound(i+1);
if(it==cards.end()){
cout<<"-1"<<endl;
return 0;
}else{
v[*it]--;
ans[i]=*it;
if(v[*it]==0){
cards.erase(*it);
}
}
}
}
int ind=k;
for(int i=0;i<=5*100000;i++){
while(v[i]){
ans[ind++]=i;
v[i]--;
}
}
reverse(ans,ans+n);
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
2672 KB |
Output is correct |
2 |
Correct |
22 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
3700 KB |
Output is correct |
2 |
Correct |
37 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
6556 KB |
Output is correct |
2 |
Correct |
80 ms |
1932 KB |
Output is correct |