import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static final StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public static int nextInt() throws IOException {
st.nextToken();
return (int) st.nval;
}
public static long nextLong() throws IOException {
st.nextToken();
return (long) st.nval;
}
public static void main(String[] args) throws IOException {
int t = nextInt();
for (int k = 0; k < t; k++) {
int n = nextInt();
long[] a = new long[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = nextInt() + a[i - 1];
}
// for (int i = 1; i <= n; i++) {
// a[i] = nextInt();
// }
// Arrays.parallelPrefix(a, Long::sum);
long n0 = Math.min(a[0], a[n]);
long nn = Math.max(a[0], a[n]);
Arrays.sort(a);
int s0 = 0,sn = 0;
for (int i = 0; i < n + 1; i++) {
if (a[i] == n0) {
s0 = i;
break;
}
}
for (int i = n; i >= 0; i--) {
if (a[i] == nn) {
sn = i;
break;
}
}
long ans = 0;
long[] b = new long[n + 1];
boolean[] f = new boolean[n + 1];
int l = 0, r = n;
for (int i = s0; i >= 0; i -= 2) {
b[l++] = a[i];
f[i] = true;
}
for (int i = sn; i <= n; i += 2) {
b[r--] = a[i];
f[i] = true;
}
for (int i = 0; i <= n; i++) {
if (!f[i])
b[l++] = a[i];
}
for (int i = 1; i <= n; i++) {
ans = Math.max(ans,Math.abs(b[i]-b[i-1]));
}
System.out.println(ans);
}
}
}
蓝桥杯--灵能传输(92%)--java--2个超时
最新推荐文章于 2024-08-18 21:36:31 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)