Submission #652420

# Submission time Handle Problem Language Result Execution time Memory
652420 2022-10-22T14:09:18 Z Johnson8033 Karte (COCI18_karte) C++14
120 / 120
103 ms 4816 KB
#include <bits/stdc++.h>
using namespace std;
int n,k,cnt;
int a[500005];
void solve(){
	cin>>n>>k;
	for (int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	reverse(a+1+n-k,a+1+n);
	for (int i=n;i>=1;i--){
		if (a[i]>cnt) cnt++;
	}
	if (cnt!=k){
		cout<<-1<<endl;
		return; 
	}
	for (int i=1;i<=n;i++){
		cout<<a[i];
		if (i<n) cout<<" ";
		else cout<<endl;
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	// cin>>t;
	while (t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1228 KB Output is correct
2 Correct 15 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2128 KB Output is correct
2 Correct 31 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 4816 KB Output is correct
2 Correct 67 ms 2252 KB Output is correct