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;
#define f first
#define s second
#define mp make_pair
#define ll long long
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;
cin>>n>>k;
int ar[n];
for(int i=0;i<n;i++){
cin>>ar[i];
}
sort(ar,ar+n);
vector<int> v;
for(int i=0;i<n-k;i++){
v.push_back(ar[i]);
}
for(int i=n-1;i>=n-k;i--){
v.push_back(ar[i]);
}
int fss=0,z=0;
for(int i=n-1;i>=0;i--){
if(fss<v[i]){
fss++;
z++;
}
}
if(z!=k){
cout<<-1<<endl;
}
else{
for(int i=0;i<n;i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
return 0;
}
# | 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... |