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 pb push_back
#define ld long double
#define ll long long
mt19937 rnd(51);
const int N = 2e6 + 10;
vector<int> g[N], used(N), mas;
int dfs(int v) {
used[v] = 1;
if (g[v].size() == 0) {
return 1;
}
vector<int> arr;
int now = -1;
for (auto to : g[v]) {
int nw = dfs(to);
if (nw > now) {
if (now != -1) mas.pb(now);
now = nw;
} else {
mas.pb(nw);
}
}
return now + 1;
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LCOAL
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d, T, ans = 0;
cin >> n >> d >> T;
vector<int> t(n), go(n, -1);
for (int i = 0; i < n; i++) {
cin >> t[i];
}
for (int i = 0; i < n; i++) {
if (t[i] > T) {
for (int j = i - 1; j >= 0; j--) {
if (t[j] + (i - j) <= T) {
go[i] = j;
ans++;
break;
}
}
} else {
ans++;
}
}
deque<pair<int,int>> q;
for (int i = n - 1; i >= 0; i--) {
while (q.size() > 0 && q.back().first > i) {
q.pop_back();
}
if (go[i] != -1) {
if (q.size() > 0) {
g[q.back().second].pb(i);
}
q.pb({go[i], i});
}
}
for (int i = n - 1; i >= 0; i--) {
if (!used[i]) {
int val = dfs(i);
mas.pb(val);
}
}
sort(mas.rbegin(), mas.rend());
for (int i = 0; i < min((int)mas.size(), d); i++) {
ans -= mas[i];
}
cout << ans << endl;
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... |