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>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define vb vector<bool>
#define vi vector<int>
#define vpii vector<pii>
#define vvb vector<vb>
#define vvi vector<vi>
#define vvpii vector<vpii>
#define sz(x) (int)(x).size()
int N, D, T;
vi F, NF;
vector<priority_queue<pii, vpii, greater<pii>>> Q;
vi P;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> D >> T;
D = min(D, N);
P.resize(N);
for (int i = 0; i < N; ++i)
cin >> P[i];
F.assign(D + 1, 0), NF.assign(D + 1, 0);
Q.resize(D + 1);
for (int i = 0; i < N; ++i)
{
for (int d = 0; d <= D; ++d)
{
NF[d] = min(F[d], NF[d]);
if (d < D)
F[d + 1] = min(F[d + 1], NF[d]);
++NF[d];
if (P[i] <= T)
{
F[d] = INT_MAX;
int nextBorder = min(N - 1, i + T - P[i]);
Q[d].push({nextBorder, NF[d] + nextBorder - i});
}
while (!Q[d].empty() && Q[d].top().first == i)
{
F[d] = min(F[d], Q[d].top().second);
Q[d].pop();
}
NF[d] = min(NF[d], F[d]);
}
}
cout << NF[D] << endl;
}
# | 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... |