leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1686.cpp (614B)


0 class Solution {
1 public:
2 int stoneGameVI(const vector<int> &aliceValues, const vector<int> &bobValues) {
3 const int n = size(aliceValues);
4 vector<int> idx(n);
6 iota(begin(idx), end(idx), 0);
7 sort(begin(idx), end(idx),
8 [&](int a, int b) { return aliceValues[a] + bobValues[a] > aliceValues[b] + bobValues[b]; });
10 int alice = 0, bob = 0, turn = 1;
11 for (const int i : idx) {
12 (turn ? alice : bob) += turn ? aliceValues[i] : bobValues[i];
13 turn = !turn;
14 }
15 return alice == bob ? 0 : alice > bob ? 1 : -1;
16 }
17 };