Problem · Binary Search
Array Operations
Learn this problemProblem statement
You are given an array of n elements and two variables, x and y.
In each operation, you can:
x from one element of the array.y from the remaining elements.Your task is to find the minimum number of operations required to make every element of the array ≤ 0.
Input Format:
n, the number of elements in the array.n space-separated integers representing the array.x and y, where x > y.Output:
Print the minimum number of operations to make each element ≤ 0.
Function
minOperations(arr: int[], x: int, y: int) → intExamples
Example 1
arr = [10, 20, 30, 40, 50]x = 5y = 2return = 14With 13 operations, the elements 30, 40, and 50 would require at least 2 + 5 + 8 = 15 selections in total, so 13 operations are impossible. With 14 operations, the shared subtraction is 28 and only 1 + 4 + 8 = 13 selections are required, so the minimum is 14.
Constraints
🍊🍊