이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> strengh(N);
for (int i = 0; i < N; ++i)
cin >> strengh[i];
vector<int> suffix(N);
for (int i = N - 1; i >= 0; --i) {
suffix[i] = strengh[i];
if (i + 1 < N)
suffix[i] = max(suffix[i], suffix[i + 1]);
}
vector<pair<int, int>> curRecords;
int ret = 0;
for (int b = 1; b < N; ++b) {
while (!curRecords.empty() and curRecords.back().first <= strengh[b - 1])
curRecords.pop_back();
curRecords.emplace_back(strengh[b - 1], b - 1);
for (int i = (int)curRecords.size() - 1; i >= 0; --i) {
auto [val, pos] = curRecords[i];
if (b - pos + b < N)
ret = max(ret, val + strengh[b] + suffix[2 * b - pos]);
if (val >= strengh[b])
break;
}
}
cout << ret << 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... |