Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*If you want something you've never had, you have to do something you never did.*/
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define ll long long
- #define pii pair<ll,ll>
- #define pll pair<ll,ll>
- #define M 100007
- #define INF 1e9
- #define INFL 1e18
- #define PI acos(-1)
- #define mp make_pair
- #define fast_in_out ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- //const ll fx[]= {+1,-1,+0,+0};
- //const ll fy[]= {+0,+0,+1,-1};
- //const ll fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
- //const ll fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
- //const ll fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
- int arr[2110];
- int dp[2110][2110];
- int n,l,h,r;
- int myfunc(int i,int time)
- {
- if(i==n)
- {
- return time>=l & time<=r;
- }
- if(dp[i][time]!=-1)
- return dp[i][time];
- int x1=0,x2=0;
- if(time>=l && time<=r)
- {
- x1=1+myfunc(i+1,(time+arr[i])%h);
- x2=1+myfunc(i+1,(time+arr[i]-1)%h);
- }
- else
- {
- x1=myfunc(i+1,(time+arr[i])%h);
- x2=myfunc(i+1,(time+arr[i]-1)%h);
- }
- dp[i][time]=max(x1,x2);
- return dp[i][time];
- }
- int main()
- {
- fast_in_out;
- cin>>n>>h>>l>>r;
- for(int i=0;i<n;i++)
- {
- cin>>arr[i];
- }
- memset(dp,-1,sizeof dp);
- int ans=myfunc(0,0);
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment