Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(), (x).end()
- using namespace std;
- using ll = long long;
- ll Solve(ll x1, ll y1, ll x2, ll y2, ll n1, ll n2) {
- return max((x1 + y1) * n1 - y1, (x2 + y2) * n2 - y2);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- ll n;
- cin >> n;
- ll x1, y1, x2, y2;
- cin >> x1 >> y1 >> x2 >> y2;
- ll left = 0;
- ll right = n;
- ll mid1;
- ll mid2;
- ll ans = 3e18;
- while (left <= right) {
- mid1 = left + (right - left) / 3;
- mid2 = right - (right - left) / 3;
- ll first = Solve(x1, y1, x2, y2, mid1, n - mid1);
- ll second = Solve(x1, y1, x2, y2, mid2, n - mid2);
- if (first <= second) {
- ans = min(ans, first);
- right = mid2 - 1;
- } else {
- ans = min(ans, second);
- left = mid1 + 1;
- }
- }
- cout << ans << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement