Submission #15377

#TimeUsernameProblemLanguageResultExecution timeMemory
15377tonyjjw달리는 게임 (kriii3_E)C++14
0 / 70
0 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]); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...