Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Exceed Threshold Value II

med
30 min
Try to solve the Minimum Operations to Exceed Threshold Value II problem.

Statement

You are given an integer array nums and an integer k.

In one operation, you perform the following actions:

  • Select the two smallest integers x and y from nums.

  • Remove x and y from nums.

  • Add min⁡(x,y)imes2+max⁡(x,y)\min(x, y) imes 2 + \max(x, y) to nums.

Return the minimum number of operations required so that every element in nums is greater than or equal to k.

Constraints:

  • 2≤2 \leq nums.length ≤2⋅105\leq 2 \cdot 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq k ≤109\leq 10^9

  • The input is generated such that an answer always exists, meaning that all elements in nums will eventually be greater than or equal to k after performing some number of operations.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Exceed Threshold Value II

med
30 min
Try to solve the Minimum Operations to Exceed Threshold Value II problem.

Statement

You are given an integer array nums and an integer k.

In one operation, you perform the following actions:

  • Select the two smallest integers x and y from nums.

  • Remove x and y from nums.

  • Add min⁡(x,y)imes2+max⁡(x,y)\min(x, y) imes 2 + \max(x, y) to nums.

Return the minimum number of operations required so that every element in nums is greater than or equal to k.

Constraints:

  • 2≤2 \leq nums.length ≤2⋅105\leq 2 \cdot 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq k ≤109\leq 10^9

  • The input is generated such that an answer always exists, meaning that all elements in nums will eventually be greater than or equal to k after performing some number of operations.