Comments
I can tell constraints: 3 <= n <= 10^5, 1 <= b < a <= 100, 1 <= hi <= 10^4. And was constraint to write order to achive answer if answer <= 10^4.
0

There was a limit to output in old constraints, see wrong accepted submissions.

But I assume that is not possible to solve this problem in the old constraints, and I can't imagine what obviously wrong greedy did in author's solve (which I didn't see, however, just suggest by solutions what was accepted).