2212. Maximum Points in an Archery Competition Medium

@problem@discussion
#Array#Bit Manipulation#Recursion#Enumeration



1/**
2 * [2212] Maximum Points in an Archery Competition
3 *
4 * Alice and Bob are opponents in an archery competition. The competition has set the following rules:
5 * <ol>
6 * 	Alice first shoots numArrows arrows and then Bob shoots numArrows arrows.
7 * 	The points are then calculated as follows:
8 * 	<ol>
9 * 		The target has integer scoring sections ranging from 0 to 11 inclusive.
10 * 		For each section of the target with score k (in between 0 to 11), say Alice and Bob have shot ak and bk arrows on that section respectively. If ak >= bk, then Alice takes k points. If ak < bk, then Bob takes k points.
11 * 		However, if ak == bk == 0, then nobody takes k points.
12 * 	</ol>
13 * 	
14 * </ol>
15 * 
16 * 	
17 * 	For example, if Alice and Bob both shot 2 arrows on the section with score 11, then Alice takes 11 points. On the other hand, if Alice shot 0 arrows on the section with score 11 and Bob shot 2 arrows on that same section, then Bob takes 11 points.
18 * 	
19 * 
20 * You are given the integer numArrows and an integer array aliceArrows of size 12, which represents the number of arrows Alice shot on each scoring section from 0 to 11. Now, Bob wants to maximize the total number of points he can obtain.
21 * Return the array bobArrows which represents the number of arrows Bob shot on each scoring section from 0 to 11. The sum of the values in bobArrows should equal numArrows.
22 * If there are multiple ways for Bob to earn the maximum total points, return any one of them.
23 *  
24 * Example 1:
25 * <img alt="" src="https://assets.leetcode.com/uploads/2022/02/24/ex1.jpg" style="width: 600px; height: 120px;" />
26 * Input: numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0]
27 * Output: [0,0,0,0,1,1,0,0,1,2,3,1]
28 * Explanation: The table above shows how the competition is scored. 
29 * Bob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47.
30 * It can be shown that Bob cannot obtain a score higher than 47 points.
31 * 
32 * Example 2:
33 * <img alt="" src="https://assets.leetcode.com/uploads/2022/02/24/ex2new.jpg" style="width: 600px; height: 117px;" />
34 * Input: numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2]
35 * Output: [0,0,0,0,0,0,0,0,1,1,1,0]
36 * Explanation: The table above shows how the competition is scored.
37 * Bob earns a total point of 8 + 9 + 10 = 27.
38 * It can be shown that Bob cannot obtain a score higher than 27 points.
39 * 
40 *  
41 * Constraints:
42 * 
43 * 	1 <= numArrows <= 10^5
44 * 	aliceArrows.length == bobArrows.length == 12
45 * 	0 <= aliceArrows[i], bobArrows[i] <= numArrows
46 * 	sum(aliceArrows[i]) == numArrows
47 * 
48 */
49pub struct Solution {}
50
51// problem: https://leetcode.com/problems/maximum-points-in-an-archery-competition/
52// discuss: https://leetcode.com/problems/maximum-points-in-an-archery-competition/discuss/?currentPage=1&orderBy=most_votes&query=
53
54// submission codes start here
55
56impl Solution {
57    pub fn maximum_bob_points(num_arrows: i32, alice_arrows: Vec<i32>) -> Vec<i32> {
58        vec![]
59    }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66    use super::*;
67
68    #[test]
69    fn test_2212() {
70    }
71}
72


Back
© 2025 bowen.ge All Rights Reserved.