-
Notifications
You must be signed in to change notification settings - Fork 1
/
mecanica.cpp
52 lines (38 loc) · 838 Bytes
/
mecanica.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
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
#define N 100010
#define int long long
using namespace std;
long long c[N];
int32_t main(){
int n, m;
cin >> n >> m;
vector <int> v;
vector <int> p;
for(int i = 0;i < n;i++){
int x;
cin >> x;
v.push_back(x);
}
for(int i = 0;i < m;i++){
int x;
cin >> x;
p.push_back(x);
}
sort(v.begin(), v.end());
sort(p.begin(), p.end());
long long res = 0;
reverse(v.begin(), v.end());
priority_queue <pair <int, int>> pq;
for(int i = 0;i < p.size();i++){
pq.push({0, i});
}
for(auto x : v){
int pos = pq.top().second, val = -x*pq.top().first;
pq.pop();
c[pos]++;
res += val;
pq.push({-c[pos]*p[pos], pos});
}
cout << res << "\n";
return 0;
}