백준 문제 1932 - 정수 삼각형

프로그래밍 이모저모/프로그래밍 2019. 8. 2. 20:57

#include <iostream>

using namespace std;

int main()
{
    int N;
    int inp;
    int Arr[200000];
    int pos = 2;
    int max = 0;
    cin >> N;
    cin >> Arr[1];
    for (int i = 2; i <= N; i++) {
        for (int j = 1; j <= i; j++) {
            cin >> inp;
            if (j == 1) {
                Arr[pos] = Arr[pos - (i - 1)] + inp;
            }
            else if (j == i) {
                Arr[pos] = Arr[pos - i] + inp;
            }
            else {
                if (Arr[pos - (i - 1)] > Arr[pos - i])
                    Arr[pos] = Arr[pos - (i - 1)] + inp;
                else Arr[pos] = Arr[pos - i] + inp;
            }
            if (max < Arr[pos])
                max = Arr[pos];
            pos++;
        }
    }
    cout << max;

    return 0;
}

'프로그래밍 이모저모 > 프로그래밍' 카테고리의 다른 글

백준 1026 - 보물  (0) 2019.08.05
백준 문제 1193 - 분수찾기  (0) 2019.08.02
백준 문제 2010 - 플러그  (0) 2019.08.02
백준 문제 2167 - 2차원 배열의 합  (0) 2019.08.02
D3.js를 다뤄보자  (0) 2018.12.23