Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define endl '\n'
- #define ll long long
- bool sortbysec(const pair<int,int> &a,
- const pair<int,int> &b)
- {
- return ((a.first-a.second) > (b.first-b.second));
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n;
- cin >> n;
- vector<pair<ll,ll>> a,b;
- for(int i=0;i<n;i++)
- {
- int x,y;
- cin >> x >> y;
- b.push_back(make_pair(x,y));
- }
- sort(b.begin(),b.end(),sortbysec);
- ll sum=0;
- for(int i=0;i<n;i++)
- {
- sum+=b[i].first*i+b[i].second*(n-(i+1));
- }
- cout << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement