Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int n, sum = 0;
- pair<int, int> a[800005];
- bool comp(pair<int,int> u, pair<int, int> v){
- return u.first-u.second < v.first-v.second;
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> n;
- for(int i = 1; i <= 2*n; i++)
- cin >> a[i].first >> a[i].second;
- sort(a + 1, a + 2*n + 1, comp);
- for(int i = 1; i <= n; i++)
- sum+= a[i].first;
- for(int i = n+1; i <= 2*n; i++)
- sum+= a[i].second;
- cout << sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement