답안 #200188

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200188 2020-02-05T16:02:38 Z Saboon Karte (COCI18_karte) C++14
120 / 120
134 ms 7148 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 5e5 + 37;

int a[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	vector<int> A, B;
	int now = 0;
	for (int i = 1; i <= n; i++){
		if (a[i] > now){
			now = min(k, now + 1);
			A.push_back(a[i]);
			continue;
		}
		B.push_back(a[i]);
	}
	if (A.size() < k)
		return cout << -1 << endl, 0;
	reverse(A.begin(), A.end());
	while (A.size() > k){
		int x = A.back();
		if (x > k)
			return cout << -1 << endl, 0;
		B.push_back(A.back());
		A.pop_back();
	}
	for (auto it : B)
		cout << it << " ";
	for (auto it : A)
		cout << it << " ";
	cout << endl;
}

Compilation message

karte.cpp: In function 'int main()':
karte.cpp:26:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (A.size() < k)
      ~~~~~~~~~^~~
karte.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (A.size() > k){
         ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1812 KB Output is correct
2 Correct 22 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 3244 KB Output is correct
2 Correct 43 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 7148 KB Output is correct
2 Correct 92 ms 4588 KB Output is correct