The Problem In Discussion is : https://codeforces.net/contest/1839/problem/D
Observations:
- The solution will be decreasing.
- Say you place some zeroes then each zero removes some contiguous subarray, the 0 is present in this subarray and subarrays of two zeroes don't overlap.
- A subarray that zero removes, give cost equal to the number of elements in the subarray.
- Now it is equivalent that each zero is present in the starting of the subarray that is is removing.
- So this can be solved with dp.
- This problem is very identical to LIS.