This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
long long a[1001];
long long dp[1001][1001];
int N;
long long solve(int pos, int cnt)
{
if(pos == N)
return 0;
long long &ret = dp[pos][cnt];
if(ret != -1)
return ret;
ret = 0;
ret = max(ret, solve(pos+1, cnt));
ret = max(ret, a[pos] * (cnt+1) + solve(pos+1, cnt+1));
return ret;
}
int main()
{
memset(dp,-1,sizeof(dp));
cin >> N;
for(int i=0; i < N; i++)
cin >> a[i];
cout << solve(0, 0);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |