You are given two independent coding problems.
Given an integer array power of length n.
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].
Make the final array nondecreasing, i.e. for all i:
power[i] <= power[i+1]
Return the minimum number of operations required.
1 <= n <= 2 * 10^5
-10^9 <= power[i] <= 10^9
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.
Maximize the sum of all primary memories across all formed pairs.
Return this maximum sum. (If you form no pairs, the sum is 0.)
1 <= m <= 2 * 10^5
0 <= memory[i] <= 10^9