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 <cmath>
#include <algorithm>
#include <stack>
#include <bitset>
#include <numeric>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using ull = unsigned long long;
using namespace std;
// const int P = 998244353;
// int norm(int x) { return x >= P ? x - P : x; }
// int reduce(int x) { return x < 0 ? x + P : x; }
// int neg(int x) { return x ? P - x : 0; }
// void add(int& x, int y) { if ((x += y - P) < 0) x += P; }
// void sub(int& x, int y) { if ((x -= y) < 0) x += P; }
// void fam(int& x, int y, int z) { x = (x + y * (ull)z) % P; }
// int mpow(int x, unsigned k) {
// if (k == 0) return 1;
// int ret = mpow(x * (ull)x % P, k >> 1);
// if (k & 1) ret = ret * (ull)x % P;
// return ret;
// }
// int quo2(int x) { return ((x & 1) ? x + P : x) >> 1; }
const int _ = 2000010;
int ans;
int t[_], l[_], r[_];
priority_queue<int> q[_];
void mer(priority_queue<int>& P, priority_queue<int>& Q) {
if (P.size() < Q.size()) swap(P, Q);
while (!Q.empty()) { P.push(Q.top()); Q.pop(); }
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int N, D, T; cin >> N >> D >> T;
for (int i = 1; i <= N; ++i) cin >> t[i];
stack<int> stk;
for (int i = N; i; --i) {
if (t[i] > T) continue;
++ans;
int lst = l[ans] = i;
r[ans] = min(N, i + T - t[i]);
q[ans].push(0);
while (true) {
if (!stk.empty() && r[ans] >= r[stk.top()]) {
int p = stk.top();
stk.pop();
int v = q[ans].top() + l[p] - lst - 1;
q[ans].pop(); q[ans].push(v);
mer(q[ans], q[p]); lst = r[p];
} else {
if (!stk.empty()) r[ans] = l[stk.top()] - 1;
int v = q[ans].top() + r[ans] - lst;
q[ans].pop(); q[ans].push(v);
break;
}
}
stk.push(ans);
}
while (!stk.empty()) { mer(q[0], q[stk.top()]); stk.pop(); }
while (D-- && !q[0].empty()) q[0].pop();
while (!q[0].empty()) { ans += q[0].top(); q[0].pop(); }
cout << ans << '\n';
return 0;
}
# | 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... |