-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB2181_CF.java
More file actions
43 lines (35 loc) · 1.22 KB
/
Copy pathB2181_CF.java
File metadata and controls
43 lines (35 loc) · 1.22 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
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
public class B2181_CF {
public static void main(String args[]){
Scanner scn = new Scanner(System.in);
int t=scn.nextInt();
while(t-->0){
int n=scn.nextInt();
int m =scn.nextInt();
PriorityQueue<Long>Alice=new PriorityQueue<>(Collections.reverseOrder());
PriorityQueue<Long>Bob= new PriorityQueue<>(Collections.reverseOrder());
for(int i=0;i<n;i++)Alice.add(scn.nextLong());
for(int i=0;i<m;i++)Bob.add(scn.nextLong());
boolean isAlice=true;
while(!Alice.isEmpty() && !Bob.isEmpty()){
if(isAlice){
long x=Alice.peek();
long y =Bob.remove();
if(y>x){
Bob.add(y-x);
}
}else{
long x=Bob.peek();
long y=Alice.remove();
if(y>x){
Alice.add(y-x);
}
}
isAlice=!isAlice;
}
System.out.println(Alice.isEmpty()?"Bob":"Alice");
}
}
}