-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps3266.cpp
More file actions
64 lines (51 loc) · 1.1 KB
/
Copy pathneps3266.cpp
File metadata and controls
64 lines (51 loc) · 1.1 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Contest : OBI 2025 - Fase 2
* Problem : Feira de Artesanato
* Link : https://neps.academy/br/exercise/3266
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
const ll MAX = 1e5 + 1;
int main() {
fastio
ll n, t, x;
cin >> n >> t;
vector<ll> id(n);
for (auto &i : id) cin >> i;
vector<multiset<ll>> types(t + 1);
multiset<pair<ll, ll>> all;
for (int i = 0; i < n; ++i) {
cin >> x;
types[id[i]].insert(x);
all.insert({x, id[i]});
}
int c; cin >> c;
ll ans = 0;
while (c--) {
cin >> x;
if (x == 0) {
if (!all.empty()) {
auto p = *all.begin();
ll price = p.first,
type = p.second;
ans += price;
all.erase(all.begin());
auto &ms = types[type];
ms.erase(ms.begin());
}
}
else {
auto &ms = types[x];
if (!ms.empty()) {
ll price = *ms.begin();
ans += price;
all.erase(all.find({price, x}));
ms.erase(ms.begin());
}
}
}
cout << ans << '\n';
return 0;
}