Submission #238615

# Submission time Handle Problem Language Result Execution time Memory
238615 2020-06-12T07:49:58 Z Vimmer Karte (COCI18_karte) C++14
12 / 120
140 ms 7800 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 = 0, i = 0, ot = 0;

    while (i < n && k > m && j < n)
    {
        if (!mk[i]) {i++; continue;}

        while (j < n && (j <= i || !mk[j] || mt[j] - ot < g[i]))
        {
            if (mkr[j]) ot++;

            j++;
        }

        if (j == n) {i++; continue;}

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

        mk[j] = 0; mkr[j] = 1;

        k--;

        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 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 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 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 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 30 ms 1940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 3320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 140 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -