Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <string>
  8. #include <cstring>
  9.  
  10. using namespace std;
  11.  
  12. const int MAXN = 5001;
  13.  
  14. int x, y, a, b, l, maxi;
  15. int m[MAXN], m1[MAXN];
  16.  
  17. void step(int l) {
  18. for (int i = 0; i <= maxi; i++) m1[i] = -1;
  19. for (int it = 0; it <= maxi; it++) {
  20. if (m[it] != -1) {
  21. if (x > y) {
  22. for(int i = 0; i <= it; i++) {
  23. int b = max(0, (l - x * i + y - 1) / y);
  24. if (m[it] < b) continue;
  25. m1[it - i] = max(m1[it - i], m[it] - b);
  26. if (l <= i * x) break;
  27. }
  28. } else {
  29. for(int i = 0; i <= m[it]; i++) {
  30. int b = max(0, (l - y * i + x - 1) / x);
  31. if (it < b) continue;
  32. m1[it - b] = max(m1[it - b], m[it] - i);
  33. if (l <= i * y) break;
  34. }
  35. }
  36. }
  37. }
  38. for (int i = 0; i <= maxi; i++) swap(m1[i], m[i]);
  39. }
  40.  
  41. bool check(int x) {
  42. for (int i = 0; i < a; i++) m[i] = -1;
  43. m[a] = b;
  44. for (int i = 0; i < l; i++) step(x);
  45. for (int i = 0; i <= a; i++) {
  46. if (m[i] != -1) return true;
  47. }
  48. return false;
  49. }
  50.  
  51. int main() {
  52. cin >> a >> x >> b >> y >> l;
  53. maxi = a;
  54. int l = 0, r = (a * x + b * y) / ::l + 1;
  55. while (r > l + 1) {
  56. int m = (l + r) / 2;
  57. if (check(m)) l = m;
  58. else r = m;
  59. }
  60. cout << l;
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement