include bits stdc using namespace std define int long long define FOR

 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,s,e) for(int i=s; i<e; i++)
#define INF 1e18
#define MAXN 10000
int n;
int a[MAXN], b[MAXN];
vector<pair<int,int>> mp;
class fastio {
public:
fastio() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
}
} __fastio;
void solve() {
cin >> n;
FOR(i,0,n) cin >> a[i];
FOR(i,0,n) cin >> b[i];
FOR(i,0,n) {
mp.push_back({a[i],b[i]});
}
sort(mp.begin(), mp.end());
int maxi = -INF, ans = 0;
set<int> track;
FOR(i,1,n) {
if(mp[i-1].first == mp[i].first) {
ans += mp[i].second;
maxi = max(maxi, mp[i].first);
track.insert(mp[i].first);
}
}
FOR(i,0,n) {
if(mp[i].first < maxi) {
for(auto i : track) {
if(mp[i].first != i) ans += mp[i].second;
}
}
}
cout << ans << endl;
}
signed main() {
__fastio;
solve();
return 0;
}