Submission #15476

#TimeUsernameProblemLanguageResultExecution timeMemory
15476tonyjjw달리는 게임 (kriii3_E)C++14
26 / 70
1 ms1108 KiB
#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]); //printf("sum: %lld\n", sum); dp[j] = max(dp[j], dp[i-1] + sum); } //printf("at %d: %lld\n", j, dp[j]); } long long ans = 0; for (int i = 0; i < n; i++) ans = max(ans, dp[i]); printf("%lld\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...