-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcardtrading.cpp
More file actions
43 lines (35 loc) · 815 Bytes
/
Copy pathcardtrading.cpp
File metadata and controls
43 lines (35 loc) · 815 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
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
using pii = pair<int, int>;
int main() {
const int maxT = 100001;
int n, t, k;
cin >> n >> t >> k;
int counter[maxT];
for (int i = 0; i < maxT; ++i) counter[i] = 0;
int x;
for (int i = 0; i < n; ++i) {
cin >> x;
counter[x]++;
}
int buy, sell;
vector<pii> profits;
for (int i = 1; i <= t; ++i) {
cin >> buy >> sell;
profits.push_back({buy * max(2 - counter[i], 0), sell * counter[i]});
}
sort(profits.begin(), profits.end(),
[](const pii &a, const pii &b) { return (a.first + a.second) < (b.first + b.second); });
long long ans = 0;
for (int i = 0; i < k; ++i) {
ans -= profits[i].first;
}
for (int i = k; i < t; ++i) {
ans += profits[i].second;
}
cout << ans;
return 0;
}