Submission #666409

#TimeUsernameProblemLanguageResultExecution timeMemory
666409MilosMilutinovicThe short shank; Redemption (BOI21_prison)C++17
0 / 100
68 ms6756 KiB
/** * 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++) { 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; } } } sort(cnt.rbegin(), cnt.rend()); for (int i = 0; i < d; i++) { ans -= cnt[i]; } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...