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)
- {
- return x.first * y.second < y.first * x.second;
- }
- 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 cur = 0;
- int cy = 0;
- for(int i = 0; i < n; i++)
- {
- if(abs(cur) > mx)
- {
- mx = abs(cur);
- if(cur < 0)
- {
- ok = 1;
- } else ok = 0;
- }
- cur += (cy + (cy + a[i].second)) * a[i].first;
- cy += a[i].second;
- }
- if(abs(cur) > mx)
- {
- mx = abs(cur);
- if(cur < 0)
- {
- ok = 1;
- } else ok = 0;
- }
- if(ok) cout << "-";
- cout << mx;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement