#include <bits/stdc++.h>
using namespace std;
const int mxN = (int)5e3+10;
int a[mxN], dp[mxN][mxN];
int main(){
int n, q,l,r; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
cin >> q;
for(int i = 1,k=2; i <= n; i++,k=i+1)
for(int j = i+2; j <= n; j++) while(2*k<=i+j)
dp[i][j]=max(dp[i][j],a[k++]+a[i]+a[j]);
for(int l = 1; l <= n; l++){
for(int i = 1,j=i+l-1; j <= n; i++,j++){
dp[i][j+1] = max(dp[i][j+1],dp[i][j]);
dp[i-1][j] = max(dp[i-1][j],dp[i][j]);
dp[i-1][j+1] = max(dp[i-1][j+1],dp[i][j]);
}
}
while(q--) cin >> l >> r,cout <<dp[l][r] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |