voidbuild(int l = 1, int r = n, int rt = 1){ if (l == r) { t[rt] = Info(l); return ; } int m = (l + r) / 2; build(lson); build(rson); t[rt] = t[rt << 1] + t[rt << 1 | 1]; } voidupdate(int i, int l = 1, int r = n, int rt = 1){ if (l == r) { t[rt] = Info(l); return ; } int m = (l + r) / 2; if (i <= m) update(i, lson); elseupdate(i, rson); t[rt] = t[rt << 1] + t[rt << 1 | 1]; }
ll cal(int mn){ vector<ll> f(n + 1, -inf), g(n + 1, -inf); for (int i = 1; i <= n; i++) { // f[i] = min(f[i - 1], g[i - 1]); f[i] = g[i - 1]; ll one = a[i]; ll two = a[i] + a[i - 1]; if (one < mn) one = inf; if (two < mn) two = inf; g[i] = min(max(one, g[i - 1]), max(two, f[i - 1])); } return g[n]; }
intmain(){ int T; scanf("%d", &T); while (T--) { scanf("%d", &n); vector<tuple<int,int,int> > teams; for (int i = 1; i <= n; i++) { scanf("%d", a + i); teams.emplace_back(a[i], i, 1); if (i > 1) { teams.emplace_back(a[i - 1] + a[i], i, 2); } } sort(begin(teams), end(teams)); mn = get<0>(teams[0]); build(); ll ans = inf; for (int i = 0, j; i < n + n - 1; i = j) { ans = min(ans, min(t[1][0][0], t[1][1][0]) - mn); j = i; while (j < n + n - 1 && get<0>(teams[i]) == get<0>(teams[j])) j++; if (j == n + n - 1) break; mn = get<0>(teams[j]); for (int k = i; k < j; k++) update(get<1>(teams[k])); } printf("%lld\n", ans); } return0; }