-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathB.java
More file actions
80 lines (66 loc) · 1.9 KB
/
B.java
File metadata and controls
80 lines (66 loc) · 1.9 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.io.*;
import java.math.*;
import java.util.*;
public class B {
public static void main(String[] args) {
try {
(new Solver()).go();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
class Solver {
public void go() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int n = in.nextInt();
int[] l = new int[n];
int[] r = new int[n];
int L = 0, R = 0;
for(int i = 0; i < n; i++) {
l[i] = in.nextInt();
r[i] = in.nextInt();
L += l[i];
R += r[i];
}
int res = Math.abs(L - R);
int save = 0;
for(int i = 0; i < n; i++) {
L += r[i] - l[i];
R += l[i] - r[i];
int cur = Math.abs(L - R);
if (cur > res) {
res = cur;
save = i + 1;
}
L -= r[i] - l[i];
R -= l[i] - r[i];
}
System.out.println(save);
out.close();
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}