답안 #84081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84081 2018-11-12T20:00:06 Z wzy Karte (COCI18_karte) C++11
120 / 120
157 ms 7976 KB
#include <bits/stdc++.h>
using namespace std;

int n , k;

int32_t main(){
	scanf("%d%d" , &n , &k);
	vector<int> big , small;
	for(int i = 0 ; i < n; i ++){
		int x;
		scanf("%d" , &x);
		if(x > k) big.push_back(x);
		else small.push_back(x);
	}
	sort(big.begin() , big.end());
	sort(small.begin() , small.end());
	if(big.size() > k){
		puts("-1");
		return 0;
	}
	else if(big.size() == k){
		vector<int> t;
		for(auto w : big) t.push_back(w);
		for(auto w : small) t.push_back(w);
		reverse(t.begin() , t.end());
		int fs = 0;
		for(auto w : t){
			if(w <= fs) continue;
			else fs++;
		}
		if(fs == k)
		for(auto w : t){
			printf("%d " , w);
		}
		else puts("-1");
	}
	else if(big.size() < k){
		int u = k;
		u-= (int) big.size();
		vector<int> pick;
		int fs = 0;
		for(auto &w : small){
			if(u == 0) break;
			if(w <= fs){
				continue;
			}
			else pick.push_back(w) , fs++  , u--  , w = -1;
		}
		if(u>0){
			puts("-1");
			return 0;
		}		
		for(auto w : big){
			pick.push_back(w);
		}
		for(auto w : small){
			if(w == -1) continue;
			pick.push_back(w);
		}
		fs = 0;
		bool can = true;
		for(auto w : pick){
			if(w <= fs) continue;
			else fs++;
		}
		if(fs == k){
			reverse(pick.begin() , pick.end());
			for(auto w : pick)
				printf("%d " , w );
		}
		else puts("-1");
	}

}

Compilation message

karte.cpp: In function 'int32_t main()':
karte.cpp:17:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(big.size() > k){
     ~~~~~~~~~~~^~~
karte.cpp:21:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  else if(big.size() == k){
          ~~~~~~~~~~~^~~~
karte.cpp:37:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  else if(big.size() < k){
          ~~~~~~~~~~~^~~
karte.cpp:61:8: warning: unused variable 'can' [-Wunused-variable]
   bool can = true;
        ^~~
karte.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d" , &n , &k);
  ~~~~~^~~~~~~~~~~~~~~~~~
karte.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &x);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 448 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 568 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2700 KB Output is correct
2 Correct 32 ms 2700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 3988 KB Output is correct
2 Correct 47 ms 3988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 7976 KB Output is correct
2 Correct 102 ms 7976 KB Output is correct