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
| func stoneGameVI(aliceValues []int, bobValues []int) int { n := len(aliceValues) prices := make([][]int, n) for i := 0; i < n; i++ { prices[i] = []int{aliceValues[i] + bobValues[i], i} } sort.Slice(prices, func(i, j int) bool { return prices[i][0] >= prices[j][0] }) alice := 0 bob := 0 for i := 0; i < n; i++ { if (i & 1) == 0 { alice += aliceValues[prices[i][1]] } else { bob += bobValues[prices[i][1]] } } if alice > bob { return 1 } else if alice < bob { return -1 } return 0 }
|