#include <bits/stdc++.h>
using namespace std;
const int nx=5e3+5;
int n, a[nx], mx[nx][nx], dp[nx][nx], q, l, r;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i], mx[i][i]=a[i];
for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++) mx[i][j]=max(mx[i][j-1], a[j]);
for (int k=2; k<=n; k++) for (int i=1; i<=n; i++) dp[i][i+k]=max({dp[i][i+k-1], dp[i+1][i+k], a[i]+a[i+k]+mx[i+1][(i+i+k)/2]});
cin>>q;
while (q--) cin>>l>>r, cout<<dp[l][r]<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4860 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4860 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
713 ms |
205384 KB |
Output is correct |
12 |
Correct |
667 ms |
205668 KB |
Output is correct |
13 |
Correct |
695 ms |
205380 KB |
Output is correct |
14 |
Correct |
694 ms |
205304 KB |
Output is correct |
15 |
Correct |
668 ms |
205408 KB |
Output is correct |
16 |
Correct |
688 ms |
204776 KB |
Output is correct |
17 |
Correct |
676 ms |
204744 KB |
Output is correct |
18 |
Correct |
679 ms |
204880 KB |
Output is correct |
19 |
Correct |
674 ms |
205384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
102 ms |
200552 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4860 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
713 ms |
205384 KB |
Output is correct |
12 |
Correct |
667 ms |
205668 KB |
Output is correct |
13 |
Correct |
695 ms |
205380 KB |
Output is correct |
14 |
Correct |
694 ms |
205304 KB |
Output is correct |
15 |
Correct |
668 ms |
205408 KB |
Output is correct |
16 |
Correct |
688 ms |
204776 KB |
Output is correct |
17 |
Correct |
676 ms |
204744 KB |
Output is correct |
18 |
Correct |
679 ms |
204880 KB |
Output is correct |
19 |
Correct |
674 ms |
205384 KB |
Output is correct |
20 |
Runtime error |
102 ms |
200552 KB |
Execution killed with signal 11 |
21 |
Halted |
0 ms |
0 KB |
- |