Submission #238611

# Submission time Handle Problem Language Result Execution time Memory
238611 2020-06-12T07:32:07 Z Vimmer Karte (COCI18_karte) C++14
36 / 120
143 ms 7416 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 500001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 2> a2;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


bool mk[N], mkr[N];

int mt[N];

int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m;

    cin >> n >> m;

    vector <int> g(n);

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

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

    int k = 0;

    for (int i = 0; i < n; i++) {mt[i] = k; if (k < g[i]) {mk[i] = 1; k++;} }

    if (k < m) {cout << -1 << endl; exit(0);}

    int j = n - 2, i = n - 1, ot = 0;

    while (k > m && i >= 0 && j >= 0)
    {
        if (mkr[i]) {i--; ot--; continue;}

        while (j >= 0 && (!mk[j] || j >= i || mt[i] - ot <= g[j])) j--;

        if (j == -1) continue;

        k--;

        swap(g[i], g[j]);

        ot++;

        mkr[j] = 1;

        i--;
    }

    reverse(g.begin(), g.end());

    if (k == m) for (auto it : g) cout << it << " "; else cout << -1 << endl;
}
# 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 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 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 3192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 143 ms 7416 KB Output isn't correct
2 Halted 0 ms 0 KB -