답안 #90238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90238 2018-12-21T01:36:07 Z updown1 Karte (COCI18_karte) C++17
120 / 120
111 ms 18068 KB
/*
last N-K are pass and are the smallest N-K (order doesn't matter)
first K are fail, from smallest to biggest
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, K)
#define ffa ffi ffj
#define s <<" "<<
#define c <<" : "<<
#define w cout
#define e endl//"\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define int ll
//500,000,000 operations
const int MAXN = 500000, INF = 10000000000;
//Global Variables
int N, K, a[MAXN], ans[MAXN];

void fail() {w<<-1<<e; exit(0);}

main() {
    //ifstream cin("test.in");
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> K;
    ffi cin >> a[i];
    sort(a, a+N);
    For (i, 0, N-K) {
        ans[i] = a[i];
        if (ans[i] > K) fail();
    }
    For (i, N-K, N) {
        ans[i] = a[N-1+N-K-i];
        /// position is N-i-1
        if (ans[i] <= N-i-1) fail();
    }
    ffi w<< ans[i]<< " "; w<<e;
}

Compilation message

karte.cpp:28:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 400 KB Output is correct
2 Correct 2 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 428 KB Output is correct
2 Correct 2 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 564 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 624 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 788 KB Output is correct
2 Correct 2 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 788 KB Output is correct
2 Correct 2 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 3468 KB Output is correct
2 Correct 17 ms 3468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 7420 KB Output is correct
2 Correct 32 ms 7420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 17772 KB Output is correct
2 Correct 76 ms 18068 KB Output is correct