Class Solution
- java.lang.Object
-
- g1701_1800.s1799_maximize_score_after_n_operations.Solution
-
public class Solution extends Object
1799 - Maximize Score After N Operations.Hard
You are given
nums, an array of positive integers of size2 * n. You must performnoperations on this array.In the
ithoperation (1-indexed) , you will:- Choose two elements,
xandy. - Receive a score of
i * gcd(x, y). - Remove
xandyfromnums.
Return the maximum score you can receive after performing
noperations.The function
gcd(x, y)is the greatest common divisor ofxandy.Example 1:
Input: nums = [1,2]
Output: 1
Explanation: The optimal choice of operations is:
v(1 * gcd(1, 2)) = 1
Example 2:
Input: nums = [3,4,6,8]
Output: 11
Explanation: The optimal choice of operations is:
(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11
Example 3:
Input: nums = [1,2,3,4,5,6]
Output: 14
Explanation: The optimal choice of operations is:
(1 * gcd(1, 5)) + (2 * gcd(2, 4)) + (3 * gcd(3, 6)) = 1 + 4 + 9 = 14
Constraints:
1 <= n <= 7nums.length == 2 * n1 <= nums[i] <= 106
- Choose two elements,
-
-
Constructor Summary
Constructors Constructor Description Solution()
-