Submission #15257

#TimeUsernameProblemLanguageResultExecution timeMemory
15257tonyjjw달리는 게임 (kriii3_E)C++14
0 / 70
0 ms9280 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <vector> using namespace std; const int N = 1024; const long long INF = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll; int n, a[N]; long long dp[N][N]; int main(void) { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = -INF; dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i-1][0]; for (int j = 1; j <= i; j++) { dp[i][j] = max(dp[i-1][j], dp[i-1][j-1] + (long long)j * a[i]); } } long long ans = 0; for (int j = 1; j <= n; j++) { ans = max(ans, dp[n][j]); } printf("%lld\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...