ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 2096번 C++ 풀이
    백준 2019. 10. 29. 00:28
    
    #include <iostream>
    #include <climits>
    #include <cstring>
    #include <queue>
    #include <algorithm>
    using namespace std;
    
    int main() {
    
    
        int n;
        cin >> n;
        int buffer[3] = {0, 0, 0};
        int previousMinAnswer[3] = {0, 0, 0};
        int minAnswer[3] = {0, 0, 0};
        int previousMaxAnswer[3] = {0, 0, 0};
        int maxAnswer[3] = {0, 0, 0};
    
        for (auto i=0; i<n; i++) {
            for (auto j=0; j<3; j++){
                cin >> buffer[j];
            }
            minAnswer[0] = buffer[0] + min(previousMinAnswer[0], previousMinAnswer[1]);
            minAnswer[1] = buffer[1] + min(min(previousMinAnswer[0], previousMinAnswer[1]), previousMinAnswer[2]);
            minAnswer[2] = buffer[2] + min(previousMinAnswer[2], previousMinAnswer[1]);
    
            maxAnswer[0] = buffer[0] + max(previousMaxAnswer[0], previousMaxAnswer[1]);
            maxAnswer[1] = buffer[1] + max(max(previousMaxAnswer[0], previousMaxAnswer[1]), previousMaxAnswer[2]);
            maxAnswer[2] = buffer[2] + max(previousMaxAnswer[2], previousMaxAnswer[1]);
    
    
            for (auto j=0; j<3; j++){
                previousMinAnswer[j] = minAnswer[j];
                previousMaxAnswer[j] = maxAnswer[j];
            }
        }
        cout << *max_element(maxAnswer, maxAnswer + 3) << ' ';
        cout << *min_element(minAnswer, minAnswer + 3);
    
        return 0;
    }

    '백준' 카테고리의 다른 글

    백준 14612번 C++ 풀이  (0) 2019.11.21
    백준 13413번 C++ 풀이  (0) 2019.11.09
    백준 2096번 C++ 풀이  (0) 2019.10.29
    백준 17070번 C++ 풀이  (0) 2019.08.30
    백준 11559번 C++ 코드  (0) 2019.08.29
    백준 2799번 C++ 풀이  (0) 2019.01.04

    댓글 0

Designed by Tistory.