-
Notifications
You must be signed in to change notification settings - Fork 0
/
1315D.cpp
39 lines (38 loc) · 897 Bytes
/
1315D.cpp
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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;scanf("%d",&n);
pair<ll,ll> a[n];
for(int i=0;i<n;++i){
ll b;scanf("%lld",&b);
a[i].first = b;
}
for(int i=0;i<n;++i){
ll b;scanf("%lld",&b);
a[i].second = b;
}
sort(a,a+n);
int i = 0;
ll cost = 0 ;
priority_queue<pair<ll,ll>> pq;
while(i<n){
int j = i;
while(i+1<n && a[i].first == a[i+1].first) ++i;
while(j<=i){
pq.push({a[j].second,a[j].first});
++j;
}
ll curr = a[i].first;
ll diff = INT_MAX;
if(i+1<n) diff = a[i+1].first-a[i].first;
while(diff && !pq.empty()){
cost += (curr-pq.top().second)*pq.top().first;
pq.pop();
--diff;
++curr;
}
++i;
}
printf("%lld\n",cost);
}