Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- const int maxN = 2010;
- int dp[maxN][maxN], a[maxN];
- int n, h, s, e;
- int solve (int idx, int sum) {
- if (idx > n) return 0;
- if (dp[idx][sum] != -1) return dp[idx][sum];
- int h1 = sum + a[idx];
- int h2 = sum + a[idx] - 1;
- int c1 = h1/ h;
- int c2 = h2 / h;
- h1 -= c1 * h;
- h2 -= c2 * h;
- int x = (h1 >= s and h1 <= e);
- int y = (h2 >= s and h2 <= e);
- return dp[idx][sum] = max(x + solve(idx + 1, h1), y + solve(idx + 1, h2));
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- //~ cin >> T;
- for (int test_case = 1; test_case <= T; ++test_case) {
- cin >> n >> h >> s >> e;
- for (int i = 1; i <= n; ++i) cin >> a[i];
- memset(dp, -1, sizeof(dp));
- cout << solve(1, 0) << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement