Created
February 9, 2019 11:00
-
-
Save Yimyujin/315ae8cf4222c9b7b8d3b7d5e0ea2ca3 to your computer and use it in GitHub Desktop.
[Baekjoon] 2096_내려가기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma warning (disable:4996) | |
/* | |
* 시간 : 28ms | |
* 메모리 : 1116kb | |
*/ | |
#include <stdio.h> | |
#define min(a,b) ((a) > (b) ? (b) : (a)) | |
#define max(a,b) ((a) < (b) ? (b) : (a)) | |
int d[2][6]; | |
int main() { | |
int n; | |
int a, b, c; | |
int k = 0; | |
scanf("%d", &n); | |
scanf("%d %d %d", &a, &b, &c); | |
d[k][0] = a; | |
d[k][1] = b; | |
d[k][2] = c; | |
d[k][3] = a; | |
d[k][4] = b; | |
d[k][5] = c; | |
for (int i = 1; i < n; ++i) { | |
scanf("%d %d %d", &a, &b, &c); | |
d[!k][0] = max(d[k][0],d[k][1]) + a; | |
d[!k][1] = max(d[k][0],max(d[k][1],d[k][2])) + b; | |
d[!k][2] = max(d[k][1],d[k][2]) + c; | |
d[!k][3] = min(d[k][3], d[k][4]) + a; | |
d[!k][4] = min(d[k][3], min(d[k][4], d[k][5])) + b; | |
d[!k][5] = min(d[k][4], d[k][5]) + c; | |
k = !k; | |
} | |
printf("%d %d\n", max(d[k][0], max(d[k][1], d[k][2])), min(d[k][3], min(d[k][4], d[k][5]))); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment