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
| #include <iostream>
using namespace std;
int n, ansMax = -1, ansMin = 2000000000, cur[2][3], tCur[2][3];
int min(int a, int b) {
return a < b ? a : b;
}
int max(int a, int b) {
return a > b ? a : b;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
int a, b, c;
cin >> cur[0][0] >> cur[0][1] >> cur[0][2];
for (int i = 0; i < 3; i++)
cur[1][i] = cur[0][i];
for (int i = 1; i < n; i++) {
cin >> a >> b >> c;
memcpy(tCur, cur, sizeof(cur));
cur[0][0] = max(tCur[0][0], tCur[0][1]) + a;
cur[0][1] = max(max(tCur[0][0], tCur[0][1]), tCur[0][2]) + b;
cur[0][2] = max(tCur[0][1], tCur[0][2]) + c;
cur[1][0] = min(tCur[1][0], tCur[1][1]) + a;
cur[1][1] = min(min(tCur[1][0], tCur[1][1]), tCur[1][2]) + b;
cur[1][2] = min(tCur[1][1], tCur[1][2]) + c;
}
for (int i = 0; i < 3; i++) {
ansMax = max(ansMax, cur[0][i]);
ansMin = min(ansMin, cur[1][i]);
}
cout << ansMax << " " << ansMin;
}
|