이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef pair <int, int> pi;
const int MAXN = 2000005;
int n, k, T, cnt;
int t[MAXN], dub[MAXN];
vector <int> v[MAXN], rem[MAXN], w;
vector <pi> r;
set <int> st;
void build () {
for (int i = 1; i <= n; i++) {
if (t[i] <= T) {
st.insert(i);
int j = i + T - t[i];
if (j + 1 <= n) rem[j + 1].push_back(i);
}
for (auto x : rem[i]) st.erase(x);
if (!st.empty()) {
int lim = *st.rbegin();
cnt++;
if (lim < i) {
while (!r.empty() && lim <= r.back().first) {
int node = r.back().second;
v[i].push_back(node);
r.pop_back();
}
r.push_back({lim, i});
}
}
}
while (!r.empty()) {
int node = r.back().second;
v[0].push_back(node);
r.pop_back();
}
}
void dfs (int x) {
int mx = 0;
for (auto sus : v[x]) {
dfs(sus);
mx = max(mx, dub[sus]);
}
dub[x] = mx + 1;
bool naso = 0;
if (x == 0) naso = 1;
for (auto sus : v[x]) {
if (dub[sus] == mx && !naso) {
naso = 1;
} else {
w.push_back(dub[sus]);
}
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> T;
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
build();
dfs(0);
sort(w.begin(), w.end());
int sol = 0;
while (!w.empty() && k > 0) {
sol += w.back();
k--;
w.pop_back();
}
cout << cnt - sol;
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... |