Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define fastread() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
- #define nl "\n"
- #define ll long long
- #define all(x) x.begin(), x.end()
- #define Unique(x) x.resize(distance(x.begin(),unique(all(x))));
- #define ff first
- #define ss second
- using namespace std;
- #define int long long
- const int N=5e4+1,M=1e9+7;
- int n,m,k,h,a[N],dp[N][1001][2];
- int func(int i,int j,int f){
- if (i>=n) return 0;
- int ans=0;
- if (dp[i][j][f]!=-1) return dp[i][j][f];
- if (a[i]<=h) ans=func(i+1,min(j+1,m),f|(min(j+1,m)>=m))+1;
- else{
- if (f) ans=func(i+k,0,0)+k;
- ans=max(ans,func(i+1,j,f));
- }
- return dp[i][j][f]=ans;
- }
- void solve(int tc){
- cin>>n>>m>>k>>h;
- for (int i=0;i<n;i++){
- cin>>a[i];
- }
- memset(dp,-1,sizeof(dp));
- cout<<func(0,0,0)<<nl;
- }
- signed main(){
- fastread();
- int T=1;//cin>>T;
- for (int i=1;i<=T;i++) solve(i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement