forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
33 lines (29 loc) · 590 Bytes
/
D.cpp
File metadata and controls
33 lines (29 loc) · 590 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bits/stdc++.h>
using namespace std;
int n;
pair <int,int> a[100100];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i].first;
for (int i = 0; i < n; i++)
cin >> a[i].second;
sort(a, a + n, greater< pair<int,int> >());
multiset <int> s;
for (int i = 1; i < n; i += 2)
{
s.insert(a[i].second);
if (i + 1 < n)
{
s.insert(a[i + 1].second);
s.erase(s.begin());
}
}
long long ans = 0;
for (auto x : s)
ans += x;
cout << ans << endl;
}