#include <bits/stdc++.h>
using namespace std;
const int mxN = (int)5e3+10;
int a[mxN], dp[mxN][mxN];
int main(){
int n, q; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
cin >> q;
for(int i = 1; i <= n; i++){
int k = i+1, mx = 0;
for(int j = i+2; j <= n; j++){
while(2*k<=i+j) mx = max(mx,a[k++]);
dp[i][j]=mx+a[i]+a[j];
}
}
for(int l = 1; l <= n; l++){
for(int i = 1; i+l-1 <= n; i++){
int j = i+l-1;
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--){
int l, r; cin >> l>> r;
cout <<dp[l][r] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
692 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
688 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
692 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
688 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
881 ms |
77020 KB |
Output is correct |
12 |
Correct |
894 ms |
76968 KB |
Output is correct |
13 |
Correct |
887 ms |
76948 KB |
Output is correct |
14 |
Correct |
887 ms |
77040 KB |
Output is correct |
15 |
Correct |
899 ms |
77004 KB |
Output is correct |
16 |
Correct |
876 ms |
76448 KB |
Output is correct |
17 |
Correct |
892 ms |
76352 KB |
Output is correct |
18 |
Correct |
893 ms |
76304 KB |
Output is correct |
19 |
Correct |
879 ms |
76876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
692 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
688 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
881 ms |
77020 KB |
Output is correct |
12 |
Correct |
894 ms |
76968 KB |
Output is correct |
13 |
Correct |
887 ms |
76948 KB |
Output is correct |
14 |
Correct |
887 ms |
77040 KB |
Output is correct |
15 |
Correct |
899 ms |
77004 KB |
Output is correct |
16 |
Correct |
876 ms |
76448 KB |
Output is correct |
17 |
Correct |
892 ms |
76352 KB |
Output is correct |
18 |
Correct |
893 ms |
76304 KB |
Output is correct |
19 |
Correct |
879 ms |
76876 KB |
Output is correct |
20 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 |
21 |
Halted |
0 ms |
0 KB |
- |