记录编号 |
602764 |
评测结果 |
AAAAA |
题目名称 |
2698.环路运输 |
最终得分 |
100 |
用户昵称 |
LikableP |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.177 s |
提交时间 |
2025-07-05 16:41:19 |
内存使用 |
3.09 MiB |
显示代码纯文本
#include <cstdio>
template <typename T> T read();
template <typename T> void write(T, char);
template <typename T> T max(T, T);
const int MAXN = 2e6 + 10;
int n;
int a[MAXN << 1];
int que[MAXN << 1], front, tail;
int ans;
int main() {
freopen("transportt.in", "r", stdin);
freopen("transportt.out", "w", stdout);
n = read<int>();
for (int i = 1; i <= n; ++i) a[i] = a[i + n] = read<int>();
que[front = tail = 1] = a[1];
for (int i = 2; i <= n << 1; ++i) {
while (front <= tail && i - que[front] > n / 2) ++front;
ans = max(ans, a[i] + a[que[front]] + i - que[front]);
while (front <= tail && a[i] - i >= a[que[tail]] - que[tail]) --tail;
que[++tail] = i;
}
write(ans, '\n');
return 0;
}
template <typename T> T max(T x, T y) {
return x > y ? x : y;
}
#define isdigit(ch) ((ch) >= '0' && (ch) <= '9')
template <typename T> T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
template <typename T> void write(T x, char ed) {
if (x < 0) x = -x, putchar('-');
static int sta[sizeof(T) << 2], top = 0;
do {
sta[++top] = x % 10;
x /= 10;
} while (x);
while (top) {
putchar(sta[top--] ^ 48);
}
putchar(ed);
}