Submission #237544

# Submission time Handle Problem Language Result Execution time Memory
237544 2020-06-07T08:36:58 Z VEGAnn Karte (COCI18_karte) C++14
120 / 120
145 ms 6904 KB
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 500100;
int n, k, a[N], b[N];

int get(int kl){
    for (int i = n - kl, j = 0; i < n; i++, j++)
        b[j] = a[i];

    for (int i = 0, j = kl; i < n - kl; i++, j++)
        b[j] = a[i];

    int cnt = 0;
    bool ok = 1;

    for (int i = 0; i < n; i++)
        if (b[i] > cnt)
            cnt++;

    return cnt;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> k;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);

    int l = k, r = n;

    while (l < r){
        int md = (l + r) >> 1;

        if (get(md) >= k)
            r = md;
        else l = md + 1;
    }

    int kl = l;

    for (int i = n - kl, j = 0; i < n; i++, j++)
        b[j] = a[i];

    for (int i = 0, j = kl; i < n - kl; i++, j++)
        b[j] = a[i];

    int cnt = 0;
    bool ok = 1;

    for (int i = 0; i < n && ok; i++)
        if (b[i] > cnt)
            cnt++;

    if (cnt == k && ok) {
        for (int i = n - 1; i >= 0; i--)
            cout << b[i] << " ";
        return 0;
    }

    cout << -1;

    return 0;
}

Compilation message

karte.cpp: In function 'int get(int)':
karte.cpp:17:10: warning: unused variable 'ok' [-Wunused-variable]
     bool ok = 1;
          ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1664 KB Output is correct
2 Correct 25 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 2936 KB Output is correct
2 Correct 46 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 6904 KB Output is correct
2 Correct 104 ms 4216 KB Output is correct