Submission #1331833

#TimeUsernameProblemLanguageResultExecution timeMemory
1331833kawhiet3단 점프 (JOI19_jumps)C++20
0 / 100
18 ms3392 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> stk;
    vector<array<int, 2>> pos;
    for (int i = 0; i < n; i++) {
        while (!stk.empty() && a[stk.back()] < a[i]) {
            stk.pop_back();
        }
        if (!stk.empty()) {
            pos.push_back({stk.back(), i});
        }
        stk.push_back(i);
    }
    vector<int> s(n + 1);
    for (int i = n - 1; i >= 0; i--) {
        s[i] = max(s[i + 1], a[i]);
    }
    int ans = 0;
    for (auto [i, j] : pos) {
        int k = 2 * j - i;
        if (k > j && k < n) {
            ans = max(ans, a[i] + a[j] + s[k + 1]);
        }
    }
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...