-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathSolution.cpp
More file actions
40 lines (34 loc) · 816 Bytes
/
Solution.cpp
File metadata and controls
40 lines (34 loc) · 816 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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n, k;
cin >> n;
cin >> k;
vector<pair<int,int>> entries(n);
for (int i = 0; i < n; i++) {
int l, t;
cin >> l;
cin >> t;
entries[i] = make_pair(l, t);
}
sort(entries.begin(), entries.end());
int counterK = 0, counterLuck = 0;
for (int i = n - 1; i >= 0; i--) {
if (entries[i].second == 1) {
if (counterK < k) {
counterK++;
counterLuck += entries[i].first;
} else {
counterLuck -= entries[i].first;
}
} else {
counterLuck += entries[i].first;
}
}
cout << counterLuck;
return 0;
}