Submission #15363

#TimeUsernameProblemLanguageResultExecution timeMemory
15363kyma123최적의 능력 구성 (kriii3_C)C++98
0 / 62
6 ms17212 KiB
#include <stdio.h> #include <vector> using namespace std; vector<long long int> dp[2]; long long int maxv(vector<long long int> &v){ long long int M = v[0]; int n = v.size(); for(int i=1;i<n;i++) M = (M>v[i]) ? M : v[i]; return M; } int main(){ int n, now, prev; scanf("%d", &n); vector<int> num; num.resize(n); for(int i=0;i<n;i++) scanf("%d", &num[i]); dp[0].resize(1000010); dp[1].resize(1000010); dp[0][0] = 0; dp[0][1] = num[0]; for(int z=1;z<n;z++){ now = z%2; prev = (z-1)%2; dp[now][0] = maxv(dp[prev]); for(int i=1;i<z+2;i++) dp[now][i] = dp[prev][i-1] + i*num[z]; } printf("%lld\n", maxv(dp[(n-1)%2])); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...