Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "BUYMILK"
- #include <iostream>
- #include <cstdio>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 1e5 + 5;
- ll A, B, C, D;
- void Read()
- {
- cin >> A >> B >> C >> D;
- }
- void Solve()
- {
- if (B <= C - D) // Sữa hộp rẻ hơn sữa chai
- cout << A / B;
- else
- {
- ll l = 1, m, h = A / (C - D);
- while (l <= h)
- {
- m = (l + h) / 2;
- if (A >= (C - D) * m && A - (m - 1) * (C - D) >= C)
- l = m + 1;
- else
- h = m - 1;
- }
- ll ans = h; // Mua h chai sữa
- A -= h * (C - D);
- ans += A / B;
- cout << ans;
- }
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment