Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define endl '\n'
  4. #define ll long long
  5. bool sortbysec(const pair<int,int> &a,
  6. const pair<int,int> &b)
  7. {
  8. return ((a.first-a.second) > (b.first-b.second));
  9. }
  10. int main()
  11. {
  12. ios_base::sync_with_stdio(false);
  13. cin.tie(0);
  14. int n;
  15. cin >> n;
  16. vector<pair<ll,ll>> a,b;
  17. for(int i=0;i<n;i++)
  18. {
  19. int x,y;
  20. cin >> x >> y;
  21. b.push_back(make_pair(x,y));
  22. }
  23. sort(b.begin(),b.end(),sortbysec);
  24. ll sum=0;
  25. for(int i=0;i<n;i++)
  26. {
  27. sum+=b[i].first*i+b[i].second*(n-(i+1));
  28. }
  29. cout << sum << endl;
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement