dynamic programming knapsack

hey please make me understand the logic of the question CodeChef: Practical coding for everyone

Hey, the editorial has been put up here - EXAM - Editorial.