Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1326E
- #include<bits/stdc++.h>
- #define ll long long
- #define fr(i,a,n) for(ll i=a;i<n;i++)
- #define ina for(ll i=0;i<n;i++)cin>>a[i];
- #define YES printf("YES\n")
- #define NO printf("NO\n")
- #define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
- using namespace std;
- ll dp[2005][2005],a[2005];
- ll n,h,l,r,ans=0;
- ll sleep(ll node,ll res,ll i)
- {
- if(dp[i][node]!=-1) {YES;return dp[i][node];}
- res=(res+node)%h;
- if(i>=n-1)
- {
- if(res>=l && res<=r)return 1; else return 0;
- }
- i++;
- ll x=sleep(a[i],res,i);
- ll y=sleep(a[i]-1,res,i);
- ll s=0;
- if(res>=l && res<=r)x++,y++;
- s=max(x,y);
- dp[i][node]=s;
- ans=max(s,ans);
- return s;
- }
- int main()
- {
- fastio;
- memset(dp,-1,sizeof dp);
- cin>>n>>h>>l>>r;
- ina;
- sleep(a[0],0,0);
- sleep(a[0]-1,0,0);
- /*fr(i,0,30)
- {
- fr(j,0,30)cout<<dp[i][j]<<" ";cout<<endl;
- }*/
- //cout<<dp[15][16]<<endl;
- cout<<ans<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement