-
Notifications
You must be signed in to change notification settings - Fork 0
/
abc074_c.cpp
43 lines (33 loc) · 892 Bytes
/
abc074_c.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
swap(c,d) ;
int answ=-1, anss=-1;
for (int qa = 0; qa*a*100ll <= f; qa++) {
for (int qb = 0; qa*a*100ll+qb*b*100ll <= f; qb++) {
for (int qd = 0; qa*a*100ll+qb*b*100ll + qd*d <= f; qd++) {
int water = qa*a*100ll + qb*b*100ll;
int sugar = qd*d;
for (int l = 0, r = f - water - sugar; l <= r; ) {
int mid = midpoint(l, r);
sugar += mid*c;
if (water + sugar <= f and e*(water) >= sugar*(100ll)) {
if (anss==-1 or anss*(sugar+water) <= sugar*(answ+anss)){
answ = water, anss = sugar;
}
l = mid + 1;
}
else r = mid -1;
sugar -= mid*c;
}
}
}
}
cout << answ + anss << ' ' << anss << '\n';
}
// AC, math, bruteforce