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<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef int64_t lld;
typedef pair<int, int> pii;
array<array<int, 5000>, 5000> ans;
vector<int> v;
signed main(){
int n;
cin >> n;
for(int i = 0; i < n; i++){
int a; cin >> a;
v.pb(a);
}
for(int i = 0; i < n; i++)
for(int j = i+2, mx = -1; j < n; j++) {
if((i+j)%2 == 0) mx = max(mx, v[i+j>>1]);
ans[i][j] = v[i]+v[j]+mx;
}
for(int l = 3; l < n; l++)
for(int i = 0, j = l; j < n; i++, j++)
ans[i][j] = max({ans[i][j], ans[i+1][j], ans[i][j-1]});
int q;
cin >> q;
while(q--){
int a, b; cin >> a >> b; cout << ans[a-1][b-1] << endl;
}
}
Compilation message (stderr)
jumps.cpp: In function 'int main()':
jumps.cpp:22:40: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
22 | if((i+j)%2 == 0) mx = max(mx, v[i+j>>1]);
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |