greedy algorithms - minimizing total payment
This answer is a hint.

Assume an optimal solution exists.  Order its choices so that they agree with your algorithm's choices for as long as possible; the order after this is unimportant.  If all of them agree, then your algo picked an optimal solution, so you're done!  If not, then at look at the first group of 3 where they disagreed.  Even though you don't know exactly what an optimal solution is, you know that one exists, and you can make changes to it -- e.g. swapping some books in its ordering -- to produce a new solution.

Can you think of a way to change it in such a way that (a) it now agrees with your algo for 1 more group of 3 and (b) its score didn't get worse?  If so, then clearly you could repeat this step until...  What happens?