比赛 |
2025暑期集训第4场 |
评测结果 |
AAAAA |
题目名称 |
环路运输 |
最终得分 |
100 |
用户昵称 |
健康铀 |
运行时间 |
0.240 s |
代码语言 |
C++ |
内存使用 |
11.97 MiB |
提交时间 |
2025-07-05 10:32:23 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("transportt.in","r",stdin);
freopen("transportt.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<long long> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
if (N == 1) {
cout << 0 << endl;
return 0;
}
int d = N / 2;
int len = 2 * N;
vector<long long> B(len);
for (int i = 0; i < len; i++) {
B[i] = A[i % N];
}
vector<long long> C(len);
for (int i = 0; i < len; i++) {
C[i] = B[i] - i;
}
deque<int> q;
long long ans = 0;
for (int j = 0; j < len; j++) {
while (!q.empty() && q.front() < j - d) {
q.pop_front();
}
if (!q.empty()) {
long long cur = C[q.front()] + B[j] + j;
if (cur > ans) {
ans = cur;
}
}
while (!q.empty() && C[q.back()] <= C[j]) {
q.pop_back();
}
q.push_back(j);
}
cout << ans << endl;
return 0;
}