/
SWAcademy 8458
45 lines (40 loc) · 1.18 KB
/
SWAcademy 8458
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
static int T, N, max;
static int[] point;
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
N = Integer.parseInt(br.readLine());
point = new int[N];
StringTokenizer st =new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
point[0] = Math.abs(x) + Math.abs(y);
max = point[0];
boolean stop = false;
for (int i = 1; i < N; i++) {
st =new StringTokenizer(br.readLine());
x = Integer.parseInt(st.nextToken());
y = Integer.parseInt(st.nextToken());
point[i] = Math.abs(x) + Math.abs(y);
max = Math.max(max, point[i]);
if(point[i]%2 != point[i-1]%2) stop = true;
}
if(stop) {
System.out.println("#"+t+" -1");
continue;
}
int sum = 0;
int cnt = 0;
while(true) {
if(sum >= max && (sum-max)%2 == 0) break;
sum += ++cnt;
}
System.out.println("#"+t+" "+cnt);
}
}
}