AcWing 5993. 回文数组
原题链接
中等
作者:
来杯whiskey
,
2025-04-03 21:44:31
· 四川
,
所有人可见
,
阅读 3
#include <bits/stdc++.h>
const int N = 1e5+10;
using i64 = long long;
int main()
{
int n;
std::cin >> n;
std::vector<i64> a(n+10);
for (int i = 1; i <= n; i ++) {
std::cin >> a[i];
}
i64 res = 0;
for (int i = 1, j = n; i <= j; i ++, j --) {
int t = std::min(a[i], a[j]);
a[i] -= t;
if (i != j) a[j] -= t;
}
for (int i = 1; i <= n; i ++) {
i64 t = a[i];
res += a[i];
a[i+1] -= std::min(t, a[i+1]);
}
std::cout << res << "\n";
return 0;
}