Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Exceed Threshold Value II

Minimum Operations to Exceed Threshold Value II combines the two smallest values into twice the smaller plus the larger, asking for the fewest operations until all values reach the threshold.

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)×2+max⁡(x,y)\min(x, y) \times 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

Minimum Operations to Exceed Threshold Value II combines the two smallest values into twice the smaller plus the larger, asking for the fewest operations until all values reach the threshold.

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)×2+max⁡(x,y)\min(x, y) \times 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.