Advertisement
nguyentien281006

ACMNB

Sep 7th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, sum = 0;
  5. pair<int, int> a[800005];
  6.  
  7. bool comp(pair<int,int> u, pair<int, int> v){
  8.     return u.first-u.second < v.first-v.second;
  9. }
  10.  
  11. int main(){
  12.     ios::sync_with_stdio(false);
  13.     cin.tie(nullptr);
  14.     cin >> n;
  15.     for(int i = 1; i <= 2*n; i++)
  16.         cin >> a[i].first >> a[i].second;
  17.     sort(a + 1, a + 2*n + 1, comp);
  18.     for(int i = 1; i <= n; i++)
  19.         sum+= a[i].first;
  20.     for(int i = n+1; i <= 2*n; i++)
  21.         sum+= a[i].second;
  22.     cout << sum;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement