Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. //1326E
  2. #include<bits/stdc++.h>
  3. #define ll long long
  4. #define fr(i,a,n) for(ll i=a;i<n;i++)
  5. #define ina for(ll i=0;i<n;i++)cin>>a[i];
  6. #define YES printf("YES\n")
  7. #define NO printf("NO\n")
  8. #define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
  9. using namespace std;
  10. ll dp[2005][2005],a[2005];
  11. ll n,h,l,r,ans=0;
  12.  
  13. ll sleep(ll node,ll res,ll i)
  14. {
  15.       if(dp[i][node]!=-1) {YES;return dp[i][node];}
  16.       res=(res+node)%h;
  17.       if(i>=n-1)
  18.       {
  19.             if(res>=l && res<=r)return 1; else return 0;
  20.  
  21.       }
  22.       i++;
  23.  
  24.       ll x=sleep(a[i],res,i);
  25.       ll y=sleep(a[i]-1,res,i);
  26.       ll s=0;
  27.       if(res>=l && res<=r)x++,y++;
  28.       s=max(x,y);
  29.       dp[i][node]=s;
  30.       ans=max(s,ans);
  31.       return s;
  32.  
  33.  
  34.  
  35.  
  36. }
  37.  
  38.  
  39.  
  40. int main()
  41. {
  42.     fastio;
  43.     memset(dp,-1,sizeof dp);
  44.     cin>>n>>h>>l>>r;
  45.  
  46.     ina;
  47.  
  48.     sleep(a[0],0,0);
  49.     sleep(a[0]-1,0,0);
  50.  
  51.     /*fr(i,0,30)
  52.     {
  53.           fr(j,0,30)cout<<dp[i][j]<<" ";cout<<endl;
  54.     }*/
  55.  
  56.  
  57.     //cout<<dp[15][16]<<endl;
  58.     cout<<ans<<endl;
  59.  
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement