# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887252 | _minhduc | The short shank; Redemption (BOI21_prison) | C++14 | 53 ms | 23252 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ii pair <int, int>
#define task "playdom"
using namespace std;
const int maxn = 2e6 + 5;
int n, D, T, t[maxn];
namespace ac {
int sum[maxn], dd[maxn];
void solve() {
int ma = 0;
priority_queue <ii, vector <ii>, greater <ii>> pq;
for (int i = 1; i <= n; i++)
sum[i] = sum[i - 1] + (t[i] > T);
for (int i = 1; i <= n; i++)
if (t[i] <= T)
ma = max (ma, T - t[i] + i);
else {
if (ma >= i)
if (pq.size() < D)
pq.push({sum[ma] - sum[i - 1], i});
else {
pq.push({sum[ma] - sum[i - 1], i});
pq.pop();
}
ma = 0;
}
while (pq.size()) {
dd[pq.top().second] = 1;
pq.pop();
}
int res = n;
for (int i = 1; i <= n; i++)
if (t[i] <= T)
ma = max (ma, T - t[i] + i);
else {
if (dd[i] == 1) {
res--;
ma = 0;
}
else
if (ma < i) {
res--;
ma = 0;
}
}
cout << res;
}
}
main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
cin >> n >> D >> T;
for (int i = 1; i <= n; i++)
cin >> t[i];
ac::solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |