#include<bits/stdc++.h>
fruit f(int ind, int n, int money, vector<fruit> &a, vector<vector<fruit>> &dp) {
fruit ans;
ans.nutrition=0;
ans.cost=0;
if(money <= 0 || ind == n ) return ans;
if (dp[ind][money].nutrition != -1) return dp[ind][money];
fruit take, notTake, val;
val.cost = 0;
val.nutrition = 0;
take.cost = 0;
notTake.cost = 0;
take.nutrition = 0;
notTake.nutrition = 0;
notTake=f(ind+1, n, money, a, dp);
if(money >= a[ind].cost) {
val.cost += a[ind].cost;
val.nutrition += a[ind].nutrition;
fruit temp = f(ind+1, n, money-a[ind].cost, a, dp);
take.cost = val.cost + temp.cost;
take.nutrition = val.nutrition + temp.nutrition;
}
if(take.nutrition == notTake.nutrition) {
ans.nutrition = take.nutrition;
ans.cost=min(take.cost, notTake.cost);
} else {
if(take.nutrition > notTake.nutrition) {
ans.nutrition = take.nutrition;
ans.cost = take.cost;
} else {
ans.nutrition = notTake.nutrition;
ans.cost = notTake.cost;
}
}
return dp[ind][money] = ans;
}
fruit getMaxNutrition(int n, int money, vector<fruit> a) {
vector<vector<fruit>> dp(n + 1, vector<fruit>(money + 1, fruit(-1, -1)));
return f(0, n, money, a, dp);
}