-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·63 lines (46 loc) · 1.13 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·63 lines (46 loc) · 1.13 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
#include <bits/stdc++.h>
using namespace std;
int makeString(vector<int> a, vector<int> b)
{
int length = 0;
int segments = 0;
for (int i = 0; i < a.size() && i < b.size(); ++i)
{
length += a[i];
length += b[i];
segments += 2;
}
if (segments <= 1)
return 0;
return length - segments;
}
int main()
{
int n;
cin >> n;
for (int c = 1; c <= n; ++c)
{
cout << "Case #" << c << ": ";
int s;
cin >> s;
vector<int> red;
vector<int> blue;
while (s--)
{
string tmp;
cin >> tmp;
char color = *tmp.rbegin();
int length = stoi(tmp.substr(0, tmp.length() - 1));
if (color == 'R')
red.push_back(length);
else
blue.push_back(length);
}
sort(red.begin(), red.end(), greater<int>());
sort(blue.begin(), blue.end(), greater<int>());
int red_first = makeString(red, blue);
int blue_first = makeString(blue, red);
cout << max(red_first, blue_first) << endl;
}
return 0;
}