이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define fi first
#define se second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
using Tree = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=1e3+5;
signed main(){
    iostream::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int tab[n];
    int dp[n][n];
    memset(dp,0,sizeof dp);
    for (int i = 0; i < n; ++i)
    {
        cin>>tab[i];
    }
    for (int i = n-3; i >= 0; i--)
    {
        int mx=tab[i+1];
        for (int j = i+2; j < n; ++j)
        {
            dp[i][j]=max(dp[i][j],max(dp[i+1][j],dp[i][j-1]));
            dp[i][j]=max(dp[i][j],tab[i]+tab[j]+mx);
            //cout <<i<<" "<<j<<" "<<dp[i][j]<<endl;
            mx=max(mx,tab[i+(j-i+1)/2]);
        }
    }
    int q;
    cin>>q;
    while(q--){
        int x,y;
        cin>>x>>y;
        x--;y--;
        cout <<dp[x][y]<<endl;
    }
}
| # | 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... |