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;
typedef long long ll;
#define endl '\n'
void solve(){
int n,d,t;
cin>>n>>d>>t;
vector<int> v(n);
for(auto &i:v) cin>>i;
vector<int> suffix(n+1);
vector<int> starts;
for(int i=n-1;i>=0;i--){
suffix[i] = suffix[i+1];
int sz = 1;
while(starts.size()){
int a = starts.back();
if(v[a] >= v[i]+(a-i)) {
starts.pop_back();
int sz2 = (starts.size() ? starts.back() - a : n - a);
suffix[i] -= min((max(0,t-v[a])),sz2);
sz += sz2;
}
else break;
}
starts.push_back(i);
suffix[i] += min((max(0,t-v[i])),sz);
}
int lst = v[0];
int prefix = (lst <= t);
int ans = prefix + suffix[1];
for(int j=1;j<n-1;j++) {
if(v[j] > lst) lst ++;
else lst = v[j];
prefix += (lst <= t);
ans = min(ans,prefix+suffix[j+1]);
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
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... |