Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<vector>
- #include<algorithm>
- #include<queue>
- #include<array>
- #define long long long
- #define nln '\n'
- const long N = 4*1e5 + 10;
- using namespace std;
- // GLobal variables: n
- long n;
- vector<long> a, b;
- priority_queue<array<long, 3>, vector<array<long,3>>, less<array<long, 3>>> pqu;
- vector<pair<long, long>> pic;
- void pick()
- {
- long n1 = n/2, n2 = n/2;
- while (!pqu.empty())
- {
- auto tak = pqu.top();
- pqu.pop();
- if (n1 == 0)
- {
- pic.push_back({tak[1], 2});
- continue;
- }
- if (n2 == 0)
- {
- pic.push_back({tak[1], 1});
- continue;
- }
- if (tak[2] == 1)
- {
- --n1;
- pic.push_back({tak[1], tak[2]});
- continue;
- }
- if (tak[2] == 2)
- {
- --n2;
- pic.push_back({tak[1], tak[2]});
- }
- }
- }
- void code()
- {
- long ans = 0;
- for (const auto &i : pic)
- //cout << i.first << ": " << i.second << nln;
- if (i.second == 1)
- ans += a[i.first];
- else
- ans += b[i.first];
- cout << ans << nln;
- }
- void data()
- {
- cin >> n;
- n *= 2;
- a.resize(n+1, 0);
- b.resize(n+1, 0);
- for (long i = 1; i <= n; ++i)
- {
- cin >> a[i] >> b[i];
- long per = -1;
- if (a[i] <= b[i])
- per = 1;
- else
- per = 2;
- pqu.push({abs(a[i]-b[i]), i, per});
- }
- }
- void process()
- {
- pick();
- code();
- }
- int main()
- {
- data();
- process();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment