제출 #1135094

#제출 시각아이디문제언어결과실행 시간메모리
1135094lopkus3단 점프 (JOI19_jumps)C++20
0 / 100
15 ms4936 KiB
#include<bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int l, r;
    cin >> l >> r;
    vector<int> suf(n + 2, 0);
    for(int i = n; i >= 1; i--) {
        suf[i] = max(suf[i + 1], a[i]);
    }
    vector<int> L(n + 1, - 1);
    stack<int> s;
    for(int i = 1; i <= n; i++) {
        while(!s.empty() && a[s.top()] < a[i]) {
            s.pop();
        }
        if(!s.empty()) {
            L[i] = s.top();
        }
        s.push(i);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(L[i] != - 1 && 2 * i - L[i] <= n) {
            ans = max(ans, a[L[i]] + a[i] + suf[2 * i - L[i]]);
        }
    }
    cout << ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...