#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <string>
#define lowbit(x) ((x)&(-x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e6 + 5;
using ll = long long ;
using ull = unsigned long long ;
int n;
ll a[MAXN];
ll f[MAXN];
inline void solve() {
int pos;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", a + i);
if (a[i] == 0)
pos = i;
}
if (n == 1)
return void(printf("No Solution\n"));
ll ans = INF;
if (pos - 1 >= 1) {
f[pos - 1] = a[pos - 1] + 1;
ans = min(f[pos - 1], ans);
for (int i = pos - 2; i >= 1; i--) {
f[i] = max(f[i + 1] - a[i], a[i] + 1);
ans = min(f[i], ans);
}
}
if (pos + 1 <= n) {
f[pos + 1] = a[pos + 1] + 1;
ans = min(f[pos + 1], ans);
for (int i = pos + 2; i <= n; i++) {
f[i] = max(f[i - 1] - a[i], a[i] + 1);
ans = min(f[i], ans);
}
}
printf("%lld\n", ans);
}
int main() {
int t;
scanf("%d", &t);
while (t--)
solve();
return 0;
}
小bai月赛49 E 禅(DP)
最新推荐文章于 2024-10-07 19:01:55 发布