Submission #265551

# Submission time Handle Problem Language Result Execution time Memory
265551 2020-08-15T00:55:30 Z shrek12357 Karte (COCI18_karte) C++14
120 / 120
383 ms 9016 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> nums;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		nums.push_back(temp);
	}
	sort(nums.begin(), nums.end());
	for (int i = 0; i < n - k; i++) {
		if (nums[i] > k) {
			cout << -1 << endl;
			return 0;
		}
	}
	multiset<int> left;
	for (int i = n - k; i < n; i++) {
		left.insert(nums[i]);
	}
	int counter = 0;
	vector<int> ans;
	while (left.size() > 0) {
		if (*left.begin() > counter) {
			counter++;
			ans.push_back(*left.begin());
			left.erase(left.begin());
		}
		else {
			break;
		}
	}
	if (left.size() != 0) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < n - k; i++) {
		cout << nums[i] << " ";
	}
	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i] << " ";
	}
	cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 2928 KB Output is correct
2 Correct 61 ms 1524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 4332 KB Output is correct
2 Correct 123 ms 2544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 383 ms 9016 KB Output is correct
2 Correct 299 ms 5600 KB Output is correct