Advertisement
tumaryui

Untitled

Nov 24th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 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. double al, be;
  14. al = (x.second*y.first);
  15. be = (y.second* x.first);
  16. return al > be;
  17. }
  18. main()
  19. {
  20. cin >> n;
  21. for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  22.  
  23. sort(a, a + n, cmp);
  24. int mx = -1;
  25. bool ok = 0;
  26. int l = 0;
  27. int cur = 0;
  28. int cx = 0, cy = 0;
  29. for(int i = 0; i < n; i++)
  30. {
  31.  
  32. cy += a[i].second;
  33. cur += (l + cy) * a[i].first;
  34. if(abs(cur) > mx)
  35. {
  36. mx = abs(cur);
  37. if(cur < 0)
  38. {
  39. ok = 1;
  40. } else ok = 0;
  41. }
  42. l = cy;
  43.  
  44. }
  45. if(ok) cout << "-";
  46. cout << mx;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement