1
vector<int> alice, bob;
2

3
struct myComp {
4
bool operator()(pair<int, int> &a, pair<int, int> &b) {
5
return alice[a.second] + bob[a.second] < alice[b.second] + bob[b.second];
6
}
7
};
8

9
class Solution {
10
public:
11
int stoneGameVI(vector<int> &aliceValues, vector<int> &bobValues) {
12
alice = aliceValues;
13
bob = bobValues;
14
priority_queue<pair<int, int>, vector<pair<int, int>>, myComp> a, b;
15

16
for (int i = 0; i < aliceValues.size(); i++) {
17
a.push({aliceValues[i], i});
18
b.push({bobValues[i], i});
19
}
20

21
int ans1, ans2;
22
ans1 = ans2 = 0;
23
int vis[100001] = {};
24

25
while (a.size()) {
26
while (a.size() && vis[a.top().second] == 1) a.pop();
27
if (a.size()) {
28
ans1 += a.top().first;
29
vis[a.top().second] = 1;
30
a.pop();
31
}
32

33
while (b.size() && vis[b.top().second] == 1) b.pop();
34
if (b.size()) {
35
ans2 += b.top().first;
36
vis[b.top().second] = 1;
37
b.pop();
38
}
39
}
40

41
if (ans1 == ans2) return 0;
42
if (ans1 > ans2) return 1;
43
return -1;
44
}
45
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0