Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <string>
- #include <vector>
- #include <sstream>
- #include <cmath>
- #include <cstring>
- #include <cstdio>
- #include <ctime>
- #include <cassert>
- using namespace std;
- const int N = 505;
- int x, a, y, b, len;
- pair<int, int> dp[N][N];
- bool can(int w)
- {
- for (int i = 0; i <= x; i++)
- for (int j = 0; j <= y; j++)
- dp[i][j] = make_pair(0, 0);
- for (int i = 0; i <= x; i++)
- for (int j = 0; j <= y; j++)
- {
- int rows = dp[i][j].first;
- int rem = dp[i][j].second;
- int rem1 = rem + a;
- int rows1 = rows + (rem1 >= w);
- if (rem1 >= w)
- rem1 = 0;
- dp[i + 1][j] = max(dp[i + 1][j], make_pair(rows1, rem1));
- int rem2 = rem + b;
- int rows2 = rows + (rem2 >= w);
- if (rem2 >= w)
- rem2 = 0;
- dp[i][j + 1] = max(dp[i][j + 1], make_pair(rows2, rem2));
- }
- for (int i = 0; i <= x; i++)
- for (int j = 0; j <= y; j++)
- if (dp[i][j].first >= len)
- return true;
- return false;
- }
- bool solve()
- {
- if (scanf("%d%d%d%d%d", &x, &a, &y, &b, &len) != 5)
- return false;
- int l = 0;
- int r = (x * a + y * b) / len + 1;
- while (r - l > 1)
- {
- int m = (l + r) / 2;
- if (can(m))
- l = m;
- else
- r = m;
- }
- printf("%d\n", l);
- return true;
- }
- int main()
- {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- #endif
- while (solve()) {}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement