Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define Task "ADVERT"
- #define watch(x) cout << #x << " = " << x << endl
- #define F first
- #define S second
- #define pb push_back
- #define mp make_pair
- using namespace std;
- typedef pair <int,int> pii;
- typedef pair <pii,int> ppi;
- typedef pair <int,pii> pip;
- typedef pair <pii,pii> ppp;
- const int oo = 1e12;
- const int MOD = 0x3f3f3f3f;
- const int MAXN = 1e5 + 1;
- int n, w, h, a[MAXN], b[MAXN];
- bool advert(double k)
- {
- double H = h, W = w;
- int i = 1;
- while (H >= 0 && i <= n)
- {
- double ai = a[i] * k, bi = b[i] * k;
- if (b[i] != b[i - 1])
- {
- W = w - ai;
- H -= bi;
- if (W < 0) return 0;
- }
- else
- {
- if (W >= ai)
- {
- W -= ai;
- }
- else
- {
- W = w - ai;
- H -= bi;
- if (W < 0) return 0;
- }
- }
- ++i;
- }
- if (H < 0) return false;
- return true;
- }
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- cin >> n >> w >> h;
- for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
- double l = 0, r = 1e9;
- while (r - l > 1e-4)
- {
- double mid = (l + r) / 2;
- if (advert(mid)) l = mid;
- else r = mid;
- }
- cout << setprecision(6) << fixed << l;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement