Array_Game
unknown
plain_text
2 years ago
1.3 kB
9
Indexable
package arrayGame;
import java.io.FileInputStream;
import java.util.Scanner;
public class arrayGame {
static int n;
static int [] arr;
static int count;
static long sum = 0;
static long sumleft;
static int max;
static long sumArr(int i, int j) {
long a = 0;
for (int k = i; k < j; k++) {
a += arr[k];
}
return a;
}
static void Try(int x, int y, int count) {
if (max < count) max = count;
sum = sumArr(x, y);
if (sum %2 != 0 || x + 1 == y) {
return;
}
sumleft = 0;
int mid = -1;
for (int i = x; i < y; i++){
sumleft += arr[i];
if (sumleft*2 == sum) {
mid = i+1;
break;
}
else if (sumleft > sum) {
return;
}
}
if(mid == -1) return;
Try(x, mid, count+1);
Try(mid, y, count+1);
}
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("D://Trainee//SRV_training//src//arrayGame//arrayGame.txt"));
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int test_case = 1; test_case <= T; test_case++){
n = sc.nextInt();
arr = new int [n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
max = 0;
Try(0, n, 0);
System.out.println(max);
}
}
}
Editor is loading...