이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: wxhtzdy
* created: 28.11.2022 15:11:47
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, d, t;
cin >> n >> d >> t;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> prv(n);
vector<int> stk;
for (int i = 0; i < n; i++) {
prv[i] = -1;
for (int j = 0; j <= i; j++) {
if (a[j] + (i - j) <= t) {
prv[i] = j;
}
}
/* while (!stk.empty() && a[stk.back()] + i - stk.back() > t) {
stk.pop_back();
}
while (!stk.empty() && a[stk.back()] - stk.back() > a[i] - i) {
stk.pop_back();
}
prv[i] = (a[i] <= t ? i : (stk.empty() ? -1 : stk.back()));
stk.push_back(i); */
}
int ans = 0;
vector<int> cnt(n);
for (int i = 0; i < n; i++) {
if (prv[i] != -1) {
ans += 1;
if (prv[i] != i) {
cnt[prv[i]] += 1;
}
}
}
set<pair<int, int>> st;
for (int i = 0; i < n; i++) {
st.emplace(cnt[i], i);
}
vector<bool> rem(n);
for (int i = 0; i < d; i++) {
auto it = prev(st.end());
int idx = it->second;
ans -= it->first;
st.erase(it);
rem[idx] = true;
for (int j = idx + 1; j < n; j++) {
if (prv[j] != -1 && prv[j] < idx) {
if (!rem[prv[j]]) {
st.erase(make_pair(cnt[prv[j]], prv[j]));
cnt[prv[j]] -= 1;
st.emplace(cnt[prv[j]], prv[j]);
prv[j] = -1;
}
}
}
}
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... |