# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
238624 |
2020-06-12T08:16:43 Z |
Vimmer |
Karte (COCI18_karte) |
C++14 |
|
134 ms |
8672 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], pr[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), v(n);
for (int i = 0; i < n; i++) {cin >> g[i]; v[i] = g[i];}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
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++;} }
for (int i = n - 1; i >= 0; i--)
{
pr[i] = 1e9;
if (i + 1 != n) pr[i] = pr[i + 1];
if (!mk[i]) pr[i] = min(pr[i], mt[i] - g[i]);
}
if (k < m) {cout << -1 << endl; exit(0);}
int l = 0;
for (int i = 0; i < n; i++)
if (l < g[i]) l++;
if (l > 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] || pr[j] < ot + 1))
{
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());
for (auto it : g) cout << it << " ";
}
# |
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 |
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 |
29 ms |
2048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
3704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
134 ms |
8672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |