Submission #497697

# Submission time Handle Problem Language Result Execution time Memory
497697 2021-12-23T16:16:12 Z LouayFarah Karte (COCI18_karte) C++17
120 / 120
122 ms 17888 KB
#include "bits/stdc++.h"

using namespace std;

#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const long long MOD = 1e9+7;
const long long INF = 1e18;

int nx[4] = {0, 0, -1, 1};
int ny[4] = {1, -1, 0, 0};


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


    ll n, k;
    cin >> n >> k;

    vector<ll> arr(n, 0);
    for(int i = 0; i<n; i++)
    {
        cin >> arr[i];
    }

    sort(arr.begin(), arr.end());

    stack<ll> res;
    for(int i = n-k; i<n; i++)
    {
        res.push(arr[i]);
    }

    for(int i = 0; i<n-k; i++)
    {
        res.push(arr[i]);
    }

    vector<ll> v;
    while(!res.empty())
    {
        v.pb(res.top());
        res.pop();
    }

    ll f = 0;
    for(int i = n-1; i>=0; i--)
    {
        if(v[i]>f)
        {
            f++;
        }
    }

    if(f==k)
    {
        for(auto elt: v)
            cout << elt << ' ';
        cout << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3876 KB Output is correct
2 Correct 15 ms 3648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 7356 KB Output is correct
2 Correct 30 ms 6852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 17888 KB Output is correct
2 Correct 82 ms 15472 KB Output is correct