Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 5005;
- struct pack {
- int v, s, in;
- };
- bool cmp_a(pack &a, pack &b) {
- return a.v < b.v;
- }
- int n;
- pack ab[N];
- long long res;
- bool check[N] = {false};
- void solve() {
- priority_queue<pair<int, int> > pq;
- res = 0;
- for(int i = 1; i <= n; i++) {
- pq.push({ab[i].s, i});
- if(i%2 == 1) {
- int gt = pq.top().first;
- int cs = pq.top().second;
- pq.pop();
- res += gt;
- check[cs] = true;
- }
- }
- cout << res << '\n';
- stack<int> index;
- for(int i = 1; i <= n; i++) {
- if(check[i]) index.push(ab[i].in);
- else {
- cout << ab[i].in << ' ' << index.top() << '\n';
- index.pop();
- }
- }
- }
- int main() {
- freopen("in.txt", "r", stdin);
- //freopen("VODIVIDE .inp", "r", stdin);
- //freopen("VODIVIDE .out", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- cin >> n;
- for(int i = 1; i <= n; i++)
- cin >> ab[i].v;
- for(int i = 1; i <= n; i++) {
- cin >> ab[i].s;
- ab[i].in = i;
- }
- sort(ab + 1, ab + n + 1, cmp_a);
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment