Submission #89693

#TimeUsernameProblemLanguageResultExecution timeMemory
89693vexKarte (COCI18_karte)C++14
120 / 120
93 ms12044 KiB
#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 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...