hiho Week 5 register

Ended

Participants:445

Verdict:Accepted
Score:100 / 100
Submitted:2014-08-02 20:54:10

Lang:G++

Edit
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
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int N;
    cin >> N;
    int res[N];
    if ( N == 0 ) {
        cout << 0 << endl;
        return 0;
    }
    cin >> res[N - 1];
    for (int i = 2; i <= N; i ++) {
        int begin = N - i;
        int val;
        cin >> val;
        res[begin] = res[begin + 1] + val;
        for (int j = begin + 1; j < N - 1; j ++) {
            cin >> val;
            res[j] = max(res[j], res[j + 1]) + val;
        }
        cin >> val;
        res[N - 1] += val;
    }
    cout << *max_element(res, res + N) << endl;
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX