Advertisement
tumaryui

Untitled

Dec 2nd, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. #define pb push_back
  4. #define pii pair<int, int>
  5.  
  6. using namespace std;
  7. double pi = acos(-1);
  8. const int N = 2e5 + 10;
  9. int n;
  10. pii a[N];
  11. bool cmp(pii x, pii y)
  12. {
  13.     return x.first * y.second < y.first * x.second;
  14. }
  15. main()
  16. {
  17.     cin >> n;
  18.     for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  19.  
  20.     sort(a, a + n, cmp);
  21.     int mx = -1;
  22.     bool ok = 0;
  23.     int cur = 0;
  24.     int cy = 0;
  25.     for(int i = 0; i < n; i++)
  26.     {
  27.         if(abs(cur) > mx)
  28.         {
  29.             mx = abs(cur);
  30.             if(cur < 0)
  31.             {
  32.                 ok = 1;
  33.             } else ok = 0;
  34.         }
  35.         cur += (cy + (cy + a[i].second)) * a[i].first; 
  36.         cy += a[i].second;
  37.     }
  38.     if(abs(cur) > mx)
  39.         {
  40.             mx = abs(cur);
  41.             if(cur < 0)
  42.             {
  43.                 ok = 1;
  44.             } else ok = 0;
  45.         }
  46.     if(ok) cout << "-";
  47.     cout << mx;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement