I think there is a solution easier than the convex hull thoughts.
We sort the powers A_i of the coconuts into increasing (non decreasing) order.
To open Z coconuts, we form a plan to hit the coconuts H_1, H_2, ... H_n times, with H_1 \le H_2 \le ... \le H_n, the sum of H_i as small as possible, and exactly Z of the H_i = A_i. (There are some details about how to execute on the plan, which I will ignore.) The problem is to choose which H_i = A_i, and which H_i to set just to satisfy the inequalities and minimize the sum of the H_i.
It happens that the optimal arrangement always has just one or two continuous blocks of H_i=A_i. And if there are two blocks, then one starts with i=1. In symbols, the optimal arrangement has the form H_1 = A_1, H_2 = A_2, ... H_i = A_i, then a gap, then H_j=A_j, H_{j+1}=A_{j+1}, ... H_k = A_k. The first sequence might have zero length, which could be viewed as i=0. After filling in the other H_i values, the H_i sequence becomes
A_1, A_2, ..., A_i, A_i, A_i, ..., A_i, A_j, A_{j+1}, ... A_{k-1}, A_k, A_k, A_k, ... A_k
With pre-calculating partial sums of A_i, for each possible i,j,k combination the sum of the H_i can be computed in constant time.
The number of H_i equal to A_i is i+(k-j+1) = Z. So given j,k, then i is fixed.
So the solution becomes iterating over all permitted values of j,k, calculating i, calculating the sum of the H_i, and minimising.
Time complexity O(N \cdot Z).
Space complexity O(N) to store the partial sums.
How do we prove the assertion that there are only two blocks? If there are two left hand edges with H_{i-1} \ne A_{i-1} and H_i = A_i, and H_{j-1} \ne A_{j-1} and H_j = A_j, then I think you can show that there is a better arrangement filling up the gap before H_i or the gap before H_j. The details of the argument would be a bit messy, but a picture or graph of the H_i and A_i may help.