1
class Solution {
2
static class Pair {
3
int sum = 0;
4
int alice = 0;
5
int bob = 0;
6

7
public Pair(int sum, int alice, int bob) {
8
this.sum = sum;
9
this.alice = alice;
10
this.bob = bob;
11
}
12
}
13

14
// class to define user defined conparator
15
static class Compare {
16

17
static void compare(Pair arr[], int n) {
18
// Comparator to sort the pair according to second element
19
Arrays.sort(
20
arr,
21
new Comparator<Pair>() {
22
@Override
23
public int compare(Pair p1, Pair p2) {
24
return p2.sum - p1.sum;
25
}
26
});
27
}
28
}
29

30
public int stoneGameVI(int[] aliceValues, int[] bobValues) {
31
int n = aliceValues.length;
32
Pair[] a = new Pair[n];
33
for (int i = 0; i < n; i++) {
34
a[i] = new Pair(aliceValues[i] + bobValues[i], aliceValues[i], bobValues[i]);
35
}
36
Compare.compare(a, n);
37
int al = 0;
38
int bo = 0;
39
for (int i = 0; i < n; i++) {
40
if (i % 2 == 0) {
41
al += a[i].alice;
42
} else {
43
bo += a[i].bob;
44
}
45
}
46
return Integer.compare(al, bo);
47
}
48
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0