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;
typedef vector<int>vi;
#define pb push_back
#define sz(v) (int)v.size()
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)
void ckmin(int &x, int y){x=min(x,y);}
void ckmax(int &x, int y){x=max(x,y);}
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
//------------------------------------------------//
const int MX=2e6+10;
const int INF=1e9;
int N,M,T;
vi a(MX);
int main(){
IO();
cin>>N>>M>>T;
FOR(i,0,N) cin>>a[i];
set<int>s;
vi val(N+1,0);
ROF(i,0,N){
if(i+1<N) val[i]+=val[i+1];
if(a[i]<=T){
int j=i+T-a[i];
val[i]++;
while(sz(s) && *s.begin()<=j){
val[i]++;
s.erase(s.begin());
}
}
else{
s.insert(i);
}
}
//FOR(i,0,N) cout << val[i] << ' '; cout << endl;
int ans=INF,r=-1,cur=0;
FOR(i,0,N){
if(a[i]<=T){
int j=i+T-a[i];
ckmax(r,j);
}
if(i<=r) cur++;
ckmin(ans,cur+val[i+1]);
}
cout << ans << endl;
}
# | 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... |