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/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
void solve() {
int n, d, t;
cin >> n >> d >> t;
int arr[n];
for (auto& a : arr) {
cin >> a;
}
int ans = 0;
vector<pair<int, int>> st, segs;
for (int i = 0; i < n; i++) {
if (t < arr[i]) {
while (sz(st) && st.back().second < i) {
st.pop_back();
}
segs.emplace_back(st.back().first, i);
} else {
ans++;
st.emplace_back(i, i + t - arr[i]);
}
}
for (int i = 0; i < d; i++) {
int psum[n] {};
for (auto& [l, r] : segs) {
psum[l]++;
psum[r]--;
}
for (int j = 0; j < n - 1; j++) {
psum[j + 1] += psum[j];
}
int ci = int(max_element(psum, psum + n) - psum);
vector<pair<int, int>> nsegs;
for (auto& [l, r] : segs) {
if (!(l <= ci && ci < r)) {
nsegs.emplace_back(l, r);
}
}
segs = nsegs;
}
cout << ans + sz(segs) << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
# | 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... |