forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbestrelayteam.cpp
65 lines (51 loc) · 1.24 KB
/
bestrelayteam.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
struct runner {
string name;
double first;
double second;
};
bool cmp(runner lhs, runner rhs) {
return lhs.second < rhs.second;
}
pair<vector<string>, double> rest(vector<runner> v, int skip) {
vector<string> ans;
ans.push_back(v[skip].name);
double total = v[skip].first;
v.erase(v.begin()+skip);
sort(v.begin(), v.end(), cmp);
total += v[0].second;
total += v[1].second;
total += v[2].second;
ans.push_back(v[0].name);
ans.push_back(v[1].name);
ans.push_back(v[2].name);
pair<vector<string>, double> p = {ans, total};
return p;
}
int main() {
int n;
cin >> n;
vector<runner> v(n);
for(int i = 0; i < n; i++) {
cin >> v[i].name >> v[i].first >> v[i].second;
}
double best = 10000;
vector<string> bestteam = {};
for(int i = 0; i < n; i++) {
pair<vector<string>, double> here = rest(v, i);
if(here.second < best) {
best = here.second;
bestteam = here.first;
}
}
cout << fixed;
cout.precision(10);
cout << best << endl;
for(auto i : bestteam) {
cout << i << endl;
}
}