-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheLeadGame.java
More file actions
51 lines (49 loc) · 1.1 KB
/
TheLeadGame.java
File metadata and controls
51 lines (49 loc) · 1.1 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
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class TheLeadGame
{
public static void leadGame() throws java.lang.Exception{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int f[] = new int[n];
int s[] = new int[n];
int lead[] = new int[n];
int player = 0;
f[0] = sc.nextInt();
s[0] = sc.nextInt();
if(f[0]>s[0]){
lead[0] = f[0]-s[0];
player =1;
}else{
lead[0] = s[0]-f[0];
player = 2;
}
int max = lead[0];
for(int i = 1 ; i<n ; i++){
f[i] = f[i-1] + sc.nextInt();
s[i] = s[i-1] + sc.nextInt();
if((f[i]-s[i])>0){
if((f[i]-s[i])>max){
lead[i] = f[i]-s[i];
max = lead[i];
player = 1;
}
}else{
if((s[i]-f[i])>max){
lead[i] = s[i]-f[i];
max = lead[i];
player = 2;
}
}
}
System.out.println(player+" "+max);
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
leadGame();
}
}