https://codeforces.net/contest/1266/problem/D
Editorial of the problem does not explains how to implement the solution .It only tells what conditions will hold after every operation and at the end (when optimal answer has been reached).
I read few submissions and they used set to solve the problem , for example : https://codeforces.net/contest/1266/submission/67106641
I will be very thankful if someone helps me to understand the solution .
I used two pointers. They respectively point a positive number and a negative number.
ohhh. can u explain why it works and how u guessed that EDIT: Lol, i skipped editorial, sry)
Noticed that there is no need to minimize the number of non-zero debts, only the total debt. So, keeping the total debt, the implementation is not unique and all of them can transform to each other. The following implementations can be all legal for the same query :
So I just choose one of them.
I'm not sure that I got your point, so feel free to ask more.