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>
using namespace std;
const int nx=2e3+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';
}
# | 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... |