-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclosingtheloop.cpp
41 lines (41 loc) · 1.07 KB
/
closingtheloop.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
// GitHub: EntityPlantt/Kattis
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool greaterInt(int a, int b) {
return a > b;
}
int main() {
int n, s, l, total;
char x;
cin >> n;
for (int c = 1; c <= n; c++) {
cin >> s;
vector <int> redKnot, blueKnot;
for (int i = 0; i < s; i++) {
cin >> l >> x;
if (x == 'B') {
blueKnot.push_back(l);
}
else {
redKnot.push_back(l);
}
}
sort(redKnot.begin(), redKnot.end(), greaterInt);
sort(blueKnot.begin(), blueKnot.end(), greaterInt);
total = 0;
while (redKnot.size() > blueKnot.size()) {
redKnot.pop_back();
}
while (redKnot.size() < blueKnot.size()) {
blueKnot.pop_back();
}
total = -2 * (int) redKnot.size();
for (int i = 0; i < redKnot.size(); i++) {
total += redKnot[i] + blueKnot[i];
}
cout << "Case #" << c << ": " << total << '\n';
}
return 0;
}