#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, 0));
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9552 KB |
Output is correct |
2 |
Correct |
10 ms |
9552 KB |
Output is correct |
3 |
Correct |
10 ms |
9552 KB |
Output is correct |
4 |
Correct |
10 ms |
9552 KB |
Output is correct |
5 |
Correct |
6 ms |
9552 KB |
Output is correct |
6 |
Correct |
10 ms |
9552 KB |
Output is correct |
7 |
Correct |
11 ms |
9552 KB |
Output is correct |
8 |
Correct |
10 ms |
9552 KB |
Output is correct |
9 |
Correct |
8 ms |
9552 KB |
Output is correct |
10 |
Correct |
11 ms |
9552 KB |
Output is correct |
11 |
Correct |
10 ms |
9552 KB |
Output is correct |
12 |
Correct |
6 ms |
9552 KB |
Output is correct |
13 |
Correct |
10 ms |
9552 KB |
Output is correct |
14 |
Correct |
6 ms |
9552 KB |
Output is correct |
15 |
Correct |
10 ms |
9552 KB |
Output is correct |
16 |
Correct |
10 ms |
9552 KB |
Output is correct |
17 |
Correct |
7 ms |
9552 KB |
Output is correct |
18 |
Correct |
6 ms |
9552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
9548 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |