Bankrupt+Baker

Wolfgang Puck has an extensive collection of cake recipes. They are separated into different binders depending on the type of cake. Although Wolfgang has restaurant franchises all over the world, he is in a period of hard times and is struggling to afford ingredients for his cakes. What cakes can he create with his small budget?

Input
On the first line you are given t (1 ≤ t ≤ 100), the number of binders. Each binder begins with title, the name of the binder, then on the next line m n b (1 ≤ m, n ≤ 100, 1 ≤ b ≤ 106) where b is Wolfgang's budget in dollars. The next m lines are given as "ingredient c" (see sample input) where c (0 ≤ c ≤ 5000) is the price in dollars for one unit of ingredient.

Then follow n recipes. Each recipe begins with name on a line of its own, then on the very next line k (1 ≤ k ≤ 100). The following k lines are of the form "requirement x" (see sample input) where x is the number of units of the ingredient requirement used in the recipe name.

Output
For each binder, output the name of the binder in uppercase letters then on separate lines a list of recipes within Wolfgang's budget in increasing order of cost. If no such recipe exists, print "Too expensive!". If recipes have the same cost print them in lexicographical order. Print a blank line after each binder.

Sample Input
2

My Favourite Cheesecake

8 3 100

sugar 4

water 0

lemonjuice 3

creamcheese 20

vanilla 5

egg 5

cream 10

strawberry 5

Strawberry Whipped Cream

2

cream 5

strawberry 3

Scrumptious Caramel Topping

3

sugar 6

water 3

lemonjuice 1

Secret Cheesecake Base

5

creamcheese 3

sugar 5

vanilla 1

egg 6

cream 1

Million Dollar Cakes

3 1 999999

costlyflour 500

gold 4500

diamond 5000

Display Cake - Do Not Eat!

3

costlyflour 100

gold 100

diamond 100

Sample Output
MY FAVOURITE CHEESECAKE

Scrumptious Caramel Topping

Strawberry Whipped Cream

MILLION DOLLAR CAKES

Too expensive!

Source Code code format="java5" import java.util.Arrays;

public class BankruptBaker { public static void main(String[] args) { String title = "My Favourite Cheesecake"; int dallar = 100;

Ingredient[] ingredients = new Ingredient[] { new Ingredient("sugar", 4), new Ingredient("water", 0), new Ingredient("lemonjuice", 3), new Ingredient("creamcheese", 20), new Ingredient("vanilla", 5), new Ingredient("egg", 5), new Ingredient("cream", 10), new Ingredient("strawberry", 5) };

Recipe[] recipes = new Recipe[] { new Recipe("Strawberry Whipped Cream", new Ingredient[] {                       new Ingredient("cream", 5),                        new Ingredient("strawberry", 3) }), new Recipe("Scrumptious Caramel Topping", new Ingredient[] {                       new Ingredient("sugar", 6), new Ingredient("water", 3),                        new Ingredient("lemonjuice", 1) }), new Recipe("Secret Cheesecake Base", new Ingredient[] {                       new Ingredient("creamcheese", 3),                        new Ingredient("sugar", 5),                        new Ingredient("vanilla", 1), new Ingredient("egg", 6),                        new Ingredient("cream", 1) }) };

binder(title, dallar, ingredients, recipes);

title = "MILLION DOLLAR CAKES"; dallar = 999999;

ingredients = new Ingredient[] { new Ingredient("costlyflour", 500), new Ingredient("gold", 4500), new Ingredient("diamond", 5000) };

recipes = new Recipe[] { new Recipe("Display Cake - Do Not Eat!", new Ingredient[] {                       new Ingredient("costlyflour", 100),                        new Ingredient("gold", 100),                        new Ingredient("diamond", 100) }) };

binder(title, dallar, ingredients, recipes); }

public static void binder(String title, int dallar, Ingredient[] ingredients, Recipe[] recipes) { // f��; ����Ѵ�. System.out.println(title);

// v�� ��Ŀ� �� ����; ����Ѵ�. for(int i = 0; i < recipes.length; i++) { recipes[i].setBudget(ingredients); }

// ����; ����8�� d���Ѵ�. Arrays.sort(recipes);

// ����� �ִ� ��8�� ���� �� �ִ� �丮�� ����Ѵ�. boolean empty = true; for(int i = 0; i < recipes.length; i++) { if(recipes[i].getBudget <= dallar) { empty = false; System.out.println(recipes[i].getName); }       }

// ���� ��ٸ� ��δٴ� �޽��� ����Ѵ�. if(empty) { System.out.println("Too expensive!!"); }

// ���� ����.       System.out.println; } }

// v���� Ŭ���� class Recipe implements Comparable { private String name;   // v���� f�� private Ingredient[] requirements;   // �䱸��

private int budget;   // v�� ����

public Recipe(String name, Ingredient[] requirements) { this.name = name; this.requirements = requirements; }

public String getName { return name; }

public Ingredient getIngredient(int index) { return requirements[index]; }

public int getSize { return requirements.length; }

public int getBudget { return budget; }

// v�� ����; ����Ѵ�. public void setBudget(Ingredient[] ingredients) { for(int i = 0; i < requirements.length; i++) { for(int j = 0; j < ingredients.length; j++) { if(requirements[i].getName.equals(ingredients[j].getName)) { budget += ingredients[j].getNum * requirements[i].getNum; }           }        }    }

// �� d�Ѵ�. public int compareTo(Recipe obj) { if(budget < obj.budget) { return -1; } else if(budget > obj.budget){ return 1; } else { return name.compareTo(obj.name); }   } }

// ��� Ŭ���� class Ingredient { private String name; private int num;

public Ingredient(String name, int num) { this.name = name; this.num = num; }

public String getName { return name; }

public int getNum { return num; } } code

Comment