forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclosingtheloop.cpp
48 lines (35 loc) · 858 Bytes
/
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
42
43
44
45
46
47
48
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++) {
vector<int> r, b;
int pieces;
cin >> pieces;
for(int j = 0; j < pieces; j++) {
int num;
char color;
cin >> num;
cin >> color;
num--;
if(color == 'R') {
r.push_back(num);
}
else {
b.push_back(num);
}
}
sort(r.rbegin(), r.rend());
sort(b.rbegin(), b.rend());
int size = min(r.size(), b.size());
int length = 0;
for(int j = 0; j < size; j++) {
length += b[j];
length += r[j];
}
cout << "Case #" << i+1 << ": " << length << endl;
}
}