Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int x,a,y,b,l;
- pair<int,int> dp[505][505];
- while (cin >> x >> a >> y >> b >> l) {
- int ll = min(a,b), rr = (a*x + b*y)/l;
- while (ll < rr) {
- int mm = (ll+rr+1)/2;
- int onea = (mm+a-1)/a;
- int oneb = (mm+b-1)/b;
- for (int i = 0; i <= y; i++) {
- dp[0][i] = make_pair(i/oneb, i%oneb);
- }
- for (int i = 1; i <= x; i++) {
- dp[i][0] = make_pair(i/onea, i%onea);
- for (int j = 1; j <= y; j++) {
- dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
- if (dp[i][j-1].second+b < mm) {
- dp[i][j] = max(dp[i][j], make_pair(dp[i][j-1].first, dp[i][j-1].second+b));
- } else {
- dp[i][j] = max(dp[i][j], make_pair(dp[i][j-1].first+1, 0));
- }
- if (dp[i-1][j].second+a < mm) {
- dp[i][j] = max(dp[i][j], make_pair(dp[i-1][j].first, dp[i-1][j].second+a));
- } else {
- dp[i][j] = max(dp[i][j], make_pair(dp[i-1][j].first+1, 0));
- }
- }
- }
- if (dp[x][y].first >= l) {
- ll = mm;
- } else {
- rr = mm-1;
- }
- }
- cout << ll << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement