Submission #15377

# Submission time Handle Problem Language Result Execution time Memory
15377 2015-07-12T06:54:55 Z tonyjjw 달리는 게임 (kriii3_E) C++14
0 / 70
0 ms 1108 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 1024;

int n;
long long inp[N], A[N], dp[N];

int main(void) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &inp[i]);
    }
    A[n-1] = inp[n-1];
    for (int i = n-2; i >= 0; i--)
        A[i] = A[i+1] + inp[i];

    dp[0] = max(inp[0], 0ll);
    for (int j = 1; j < n; j++) {
        dp[j] = dp[j-1];
        long long sum = 0;
        for (int i = j; i >= 0; i--) {
            sum += (long long)(A[i] - A[j+1]);
            dp[j] = max(dp[j], (i >= 2)? dp[i-2]: 0 + sum);
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; i++)
        ans = max(ans, dp[i]);
    printf("%lld\n", ans);
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1108 KB Output is correct
2 Incorrect 0 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -