WA in Online Shopping pls help....

here is my solution which clears subtask 2 but gives wa in subtask 1.
The logic seems correct. (I saw the editorial and some solutions) but I cant seem to figure out why it gives wa in subtask 1 ans 3 pls help…

Question link : COUPON Problem - CodeChef

Solution link : CodeChef: Practical coding for everyone

Thanks.