Advertisement
Arrias

Untitled

Dec 22nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. const int N = 155;
  8. const int INF = 2e9;
  9.  
  10. int dp[N][N];
  11.  
  12. int main()
  13. {
  14. ios::sync_with_stdio(false);
  15. cin.tie(0);
  16.  
  17. freopen("bridge.in", "r", stdin);
  18. freopen("bridge.out", "w", stdout);
  19.  
  20. int x, a, y, b, l;
  21. cin >> x >> a >> y >> b >> l;
  22.  
  23. int lo = min(a,b) + 1, hi = 50000;
  24.  
  25. while (lo < hi)
  26. {
  27. int mid = (lo + hi) / 2;
  28.  
  29. bool good = 1;
  30.  
  31. fill_n(&dp[0][0], N * N, INF);
  32.  
  33. dp[0][0] = 0;
  34.  
  35. for (int i = 1; i <= l; ++i)
  36. {
  37. for (int j = 0; j <= x; ++j)
  38. {
  39. for (int kx = 0; kx <= j; ++kx)
  40. {
  41. int ky = max(0, (mid - kx * a + b - 1) / b);
  42. dp[i][j] = min(dp[i][j], dp[i - 1][j - kx] + ky);
  43. }
  44. }
  45. }
  46.  
  47. good = 0;
  48. for (int i = 0; i <= x; ++i)
  49. good |= (dp[l][i] <= y);
  50.  
  51. if (good)
  52. lo = mid + 1;
  53. else
  54. hi = mid;
  55.  
  56. }
  57.  
  58. cout << lo - 1 << "\n";
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement