728x90
https://www.acmicpc.net/problem/2096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(3);
vector<int> minDp(3);
vector<int> maxDp(3);
for (int i = 0; i < 3; i++) {
cin >> v[i];
minDp[i] = v[i];
maxDp[i] = v[i];
}
for (int i = 1; i < n; i++) {
cin >> v[0] >> v[1] >> v[2];
int a1 = minDp[0];
int b1 = minDp[1];
int c1 = minDp[2];
int a2 = maxDp[0];
int b2 = maxDp[1];
int c2 = maxDp[2];
minDp[0] = (min(a1 + v[0], b1 + v[0]));
minDp[1] = (min(min(a1 + v[1], b1 + v[1]), c1 + v[1]));
minDp[2] = (min(b1 + v[2], c1 + v[2]));
maxDp[0] = (max(a2 + v[0], b2 + v[0]));
maxDp[1] = (max(max(a2 + v[1], b2 + v[1]), c2 + v[1]));
maxDp[2] = (max(b2 + v[2], c2 + v[2]));
}
int minSum = min(min(minDp[0], minDp[1]), minDp[2]);
int maxSum = max(max(maxDp[0], maxDp[1]), maxDp[2]);
cout << maxSum << " " << minSum;
return 0;
}
728x90
'알고리즘 문제' 카테고리의 다른 글
[백준] 1309번 동물원 (0) | 2020.03.17 |
---|---|
[백준] 2225 합분해 (0) | 2020.03.16 |
[백준] 2631번 줄세우기 (0) | 2020.03.15 |
[백준] 9084번 동전 (0) | 2020.03.14 |
[백준] 1937번 욕심쟁이 판다 (0) | 2020.03.14 |