-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.cpp
40 lines (30 loc) · 812 Bytes
/
1.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
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <numeric>
#include <string>
#include <vector>
int main(int argc, char *argv[]) {
if (argc < 2) {
return 1;
}
std::ifstream file(argv[1]);
std::vector<std::vector<int>> c;
auto v = std::vector<int>();
for (std::string line; std::getline(file, line);) {
if (line.empty()) {
c.push_back(v);
v = std::vector<int>();
continue;
}
v.push_back(std::stoi(line));
}
std::vector<int> cc(c.size());
std::transform(c.begin(), c.end(), cc.begin(),
[](auto v) { return std::reduce(v.begin(), v.end()); });
std::sort(cc.begin(), cc.end());
std::cout << cc.back() << std::endl;
std::cout << std::reduce(cc.end() - 3, cc.end()) << std::endl;
return 0;
}