Advertisement
nightwing_808

Untitled

Jul 8th, 2025
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. #define fastread() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
  3. #define nl "\n"
  4. #define ll long long
  5. #define all(x) x.begin(), x.end()
  6. #define Unique(x) x.resize(distance(x.begin(),unique(all(x))));
  7. #define ff first
  8. #define ss second
  9. using namespace std;
  10. #define int long long
  11. const int N=5e4+1,M=1e9+7;
  12. int n,m,k,h,a[N],dp[N][1001][2];
  13. int func(int i,int j,int f){
  14.     if (i>=n) return 0;
  15.     int ans=0;
  16.     if (dp[i][j][f]!=-1) return dp[i][j][f];
  17.     if (a[i]<=h) ans=func(i+1,min(j+1,m),f|(min(j+1,m)>=m))+1;
  18.     else{
  19.         if (f) ans=func(i+k,0,0)+k;
  20.         ans=max(ans,func(i+1,j,f));
  21.     }
  22.     return dp[i][j][f]=ans;
  23. }
  24. void solve(int tc){
  25.     cin>>n>>m>>k>>h;
  26.     for (int i=0;i<n;i++){
  27.         cin>>a[i];
  28.     }
  29.     memset(dp,-1,sizeof(dp));
  30.     cout<<func(0,0,0)<<nl;
  31. }
  32. signed main(){
  33.     fastread();
  34.     int T=1;//cin>>T;
  35.     for (int i=1;i<=T;i++) solve(i);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement