COOK104B testCase

hi i am not able to understand the test case of third question march cook off 2019.
Can anybody tell me how we get 7 as the answer.Thankyou.

question link - CodeChef: Practical coding for everyone

and this one

5 3 14

1 8 2

1 4 2

1 13 1

2 13 2

2 9 1

14 7 48

Ans - 5

You can buy album 1 at cost of 10 and can also buy last song at 13 to total cost = 23 and greatness is 2+2+1+2 = 7…
For the second test case,
Buy album 1 at cost 14 and you will get 2+2+1=5 greatness…
Basically there are individual prices for each song and if you buy whole set of song(album) then you may get some discount on price…

Thankyou and fuck i read input in reverse order which means I read it as (vi,pi,ai) and now when you explain it to me i realize i read it wrong fuck me …and thankyou…