You are given two independent coding problems.
Problem 1: Minimum range-increments to make an array nondecreasing
Given an integer array power of length n.
Operation
In one operation, choose indices l and r with 0 <= l <= r < n, and add 1 to every element in the contiguous subarray power[l..r].
Goal
Make the final array nondecreasing, i.e. for all i:
Return the minimum number of operations required.
Constraints (typical for OA)
-
1 <= n <= 2 * 10^5
-
-10^9 <= power[i] <= 10^9
Problem 2: Pair servers to maximize total primary memory
Given an integer array memory of length m, where each element is the memory capacity of one server.
You may choose some servers and partition the chosen servers into disjoint pairs. For each pair, you must assign one server as primary and the other as backup such that:
-
backup_memory >= primary_memory
Each server can be used at most once and cannot belong to multiple pairs.
Goal
Maximize the sum of all primary memories across all formed pairs.
Return this maximum sum. (If you form no pairs, the sum is 0.)
Constraints (typical for OA)
-
1 <= m <= 2 * 10^5
-
0 <= memory[i] <= 10^9