Advertisement
newb_ie

Untitled

Dec 8th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. const int maxN = 2010;
  6. int dp[maxN][maxN], a[maxN];
  7. int n, h, s, e;
  8.  
  9. int solve (int idx, int sum) {
  10. if (idx > n) return 0;
  11. if (dp[idx][sum] != -1) return dp[idx][sum];
  12. int h1 = sum + a[idx];
  13. int h2 = sum + a[idx] - 1;
  14. int c1 = h1/ h;
  15. int c2 = h2 / h;
  16. h1 -= c1 * h;
  17. h2 -= c2 * h;
  18. int x = (h1 >= s and h1 <= e);
  19. int y = (h2 >= s and h2 <= e);
  20. return dp[idx][sum] = max(x + solve(idx + 1, h1), y + solve(idx + 1, h2));
  21. }
  22.  
  23. int main () {
  24. ios::sync_with_stdio(false);
  25. cin.tie(nullptr);
  26. cout.tie(nullptr);
  27. int T = 1;
  28. //~ cin >> T;
  29. for (int test_case = 1; test_case <= T; ++test_case) {
  30. cin >> n >> h >> s >> e;
  31. for (int i = 1; i <= n; ++i) cin >> a[i];
  32. memset(dp, -1, sizeof(dp));
  33. cout << solve(1, 0) << '\n';
  34. }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement