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>
#define maxn 500005
#define MAX 500000
using namespace std;
int n,k;
int cnt[maxn]={0};
vector<int>sol;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>k;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
cnt[x]++;
}
int brv=0;
for(int i=k+1;i<=MAX;i++)brv+=cnt[i];
if(brv>k)
{
cout<<"-1"<<endl;
return 0;
}
int br=0;
for(int i=0;i<=k && br+brv<k;i++)
{
int d=min(min(cnt[i],i-br),k-br-brv);
br+=d;
cnt[i]-=d;
for(int j=0;j<d;j++)sol.push_back(i);
}
br+=brv;
if(br<k)
{
cout<<"-1"<<endl;
return 0;
}
for(int i=k+1;i<=MAX;i++)
for(int j=0;j<cnt[i];j++)sol.push_back(i);
for(int i=0;i<=k;i++)
for(int j=0;j<cnt[i];j++)sol.push_back(i);
for(int i=n-1;i>=0;i--)cout<<sol[i]<<" ";
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... |