답안 #373744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373744 2021-03-05T14:52:09 Z vishesh312 Karte (COCI18_karte) C++17
120 / 120
125 ms 7528 KB
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

using ll = long long;
const int mod = 1e9+7;

void solve(int tc) {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &x : v) cin >> x;
    sort(all(v));
    vector<int> ans;
    for (int i = 0; i < n-k; ++i) {
        ans.push_back(v[i]);
        if (v[i] > k) {
            cout << "-1\n";
            return;
        }
    }
    for (int i = n-k; i < n; ++i) {
        ans.push_back(v[n-1+n-k-i]);
        if (ans.back() <= n-1-i) {
            cout << "-1\n";
            return;
        }
    }
    for (int x : ans) cout << x << " "; cout << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) solve(i);
    return 0;
}

Compilation message

karte.cpp: In function 'void solve(int)':
karte.cpp:36:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   36 |     for (int x : ans) cout << x << " "; cout << '\n';
      |     ^~~
karte.cpp:36:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   36 |     for (int x : ans) cout << x << " "; cout << '\n';
      |                                         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2028 KB Output is correct
2 Correct 18 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 3304 KB Output is correct
2 Correct 34 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 7140 KB Output is correct
2 Correct 82 ms 7528 KB Output is correct