Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define pb push_back
- #define pii pair<int, int>
- using namespace std;
- double pi = acos(-1);
- const int N = 2e5 + 10;
- int n;
- pii a[N];
- bool cmp(pii x, pii y)
- {
- double al, be;
- al = (x.second*y.first);
- be = (y.second* x.first);
- return al > be;
- }
- main()
- {
- cin >> n;
- for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
- sort(a, a + n, cmp);
- int mx = -1;
- bool ok = 0;
- int l = 0;
- int cur = 0;
- int cx = 0, cy = 0;
- for(int i = 0; i < n; i++)
- {
- cy += a[i].second;
- cur += (l + cy) * a[i].first;
- if(abs(cur) > mx)
- {
- mx = abs(cur);
- if(cur < 0)
- {
- ok = 1;
- } else ok = 0;
- }
- l = cy;
- }
- if(ok) cout << "-";
- cout << mx;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement