1686. Stone Game VI Medium

@problem@discussion
#Array#Math#Greedy#Sorting#Heap (Priority Queue)#Game Theory



1/**
2 * [1686] Stone Game VI
3 *
4 * Alice and Bob take turns playing a game, with Alice starting first.
5 * There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.
6 * You are given two integer arrays of length n, aliceValues and bobValues. Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the i^th stone.
7 * The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play optimally. Both players know the other's values.
8 * Determine the result of the game, and:
9 * 
10 * 	If Alice wins, return 1.
11 * 	If Bob wins, return -1.
12 * 	If the game results in a draw, return 0.
13 * 
14 *  
15 * Example 1:
16 * 
17 * Input: aliceValues = [1,3], bobValues = [2,1]
18 * Output: 1
19 * Explanation:
20 * If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.
21 * Bob can only choose stone 0, and will only receive 2 points.
22 * Alice wins.
23 * 
24 * Example 2:
25 * 
26 * Input: aliceValues = [1,2], bobValues = [3,1]
27 * Output: 0
28 * Explanation:
29 * If Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.
30 * Draw.
31 * 
32 * Example 3:
33 * 
34 * Input: aliceValues = [2,4,3], bobValues = [1,6,7]
35 * Output: -1
36 * Explanation:
37 * Regardless of how Alice plays, Bob will be able to have more points than Alice.
38 * For example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.
39 * Bob wins.
40 * 
41 *  
42 * Constraints:
43 * 
44 * 	n == aliceValues.length == bobValues.length
45 * 	1 <= n <= 10^5
46 * 	1 <= aliceValues[i], bobValues[i] <= 100
47 * 
48 */
49pub struct Solution {}
50
51// problem: https://leetcode.com/problems/stone-game-vi/
52// discuss: https://leetcode.com/problems/stone-game-vi/discuss/?currentPage=1&orderBy=most_votes&query=
53
54// submission codes start here
55
56impl Solution {
57    pub fn stone_game_vi(alice_values: Vec<i32>, bob_values: Vec<i32>) -> i32 {
58        0
59    }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66    use super::*;
67
68    #[test]
69    fn test_1686() {
70    }
71}
72


Back
© 2025 bowen.ge All Rights Reserved.