Advertisement
Salehisayev

sdd

Mar 10th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. #define pii pair<ll , ll>
  6. #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  7. #define MAXX  200005
  8.  
  9.  
  10. ll max(ll a, ll b){
  11.     if(a > b) return a;
  12.     return b;
  13. }
  14.  
  15. multiset<ll> ms;
  16. multiset<ll>::iterator it;
  17.  
  18. ll s , n;
  19. int a , b;
  20. ll c[MAXX];
  21.  
  22. int main()
  23. {
  24.     _FastIO;
  25.     cin >> n;
  26.     for(ll i = 0; i < 2 * n; i++){
  27.         cin >> a >> b;
  28.         s += min(a , b); //putalarin minumlari topladiq
  29.         ms.insert(a - b);//ferqlerini sortlayiriq multisetle time low az
  30.     }
  31.     ll y = 0; //saygac
  32.     for(it = ms.begin(); it != ms.end(); it++){
  33.         c[y] = *it;
  34.         y++;
  35.     }
  36.     for(ll i = 0; i < n; i++){
  37.         s += max(0 , (-1 * c[i])); // axsam yeyirik min top ucun en azi sifir yeye bilerik yoxsa a - b ucun -1 * c[i] tersi b cixiriq
  38.     }
  39.     for(ll i = n; i < 2 * n; i++){
  40.         s += max(0 , c[i]);//seher yeyirik a - b a uste gelirik 1 * c[i] musbet
  41.     }
  42.     // s += max(0 , nese) onsuda s azalasi deyil cunki hamisin min cemi
  43.     cout << s << endl;
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement