Submission #1018708

# Submission time Handle Problem Language Result Execution time Memory
1018708 2024-07-10T08:45:41 Z vjudge1 Karte (COCI18_karte) C++17
120 / 120
131 ms 12120 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for (int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	multiset<int> se;
	for (int i=n-1;i>n-1-k;i--)
		se.insert(a[i]);
	int cnt[k+1]={};
	for (int i=0;i<n-k;i++)
	{
		if (a[i]>k)
			return cout<<-1<<endl, 0;
		cnt[a[i]]++;
	}
	vector<int> ans;
	for (int i=0;i<=k;i++)
	{
		while (cnt[i]--)
			ans.push_back(i);
		if (i<k)
		{
			auto x=se.begin();
			if (*x<=i)
			{
				cout<<-1<<endl;
				return 0;
			}
			ans.push_back(*x);
			se.erase(x);
		}
	}
	reverse(ans.begin(),ans.end());
	for (int i:ans)
		cout<<i<<' ';
	cout<<endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 3864 KB Output is correct
2 Correct 23 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 5664 KB Output is correct
2 Correct 53 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 12120 KB Output is correct
2 Correct 108 ms 8420 KB Output is correct