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;
const int MX=2e6+5;
int N,D,T;
int A[MX],B[MX];
bool C[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N>>D>>T;
for(int i=1;i<=N;i++) {
cin>>A[i];
B[i]=A[i]-i;
}
for(int d=0;d<D;d++) {
vector<int> stk;
vector<int> cnt(N+1);
for(int i=1;i<=N;i++) {
while(stk.size() && B[stk.back()]>=B[i]) stk.pop_back();
if(A[i]<=T) {
stk.push_back(i);
} else {
if(stk.size() && A[stk.back()]+i-stk.back()) cnt[stk.back()]+=1;
}
if(C[i]) stk.clear();
}
int arg=0;
for(int i=1;i<=N;i++) {
if(cnt[i]>cnt[arg]) arg=i;
}
C[arg]=true;
}
vector<int> stk;
int ans=0;
for(int i=1;i<=N;i++) {
while(stk.size() && B[stk.back()]>=B[i]) stk.pop_back();
if(A[i]<=T) {
ans++;
} else {
if(stk.size() && A[stk.back()]+i-stk.back()<=T) ans++;
}
if(C[i]) stk.clear();
}
cout<<ans<<'\n';
}
# | 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... |