Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define pii pair<ll , ll>
- #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define MAXX 200005
- ll max(ll a, ll b){
- if(a > b) return a;
- return b;
- }
- multiset<ll> ms;
- multiset<ll>::iterator it;
- ll s , n;
- int a , b;
- ll c[MAXX];
- int main()
- {
- _FastIO;
- cin >> n;
- for(ll i = 0; i < 2 * n; i++){
- cin >> a >> b;
- s += min(a , b); //putalarin minumlari topladiq
- ms.insert(a - b);//ferqlerini sortlayiriq multisetle time low az
- }
- ll y = 0; //saygac
- for(it = ms.begin(); it != ms.end(); it++){
- c[y] = *it;
- y++;
- }
- for(ll i = 0; i < n; i++){
- 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
- }
- for(ll i = n; i < 2 * n; i++){
- s += max(0 , c[i]);//seher yeyirik a - b a uste gelirik 1 * c[i] musbet
- }
- // s += max(0 , nese) onsuda s azalasi deyil cunki hamisin min cemi
- cout << s << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement