import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeSet;
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer("");
int testcases=Integer.parseInt(br.readLine());
if(testcases<1 || testcases>100)
System.exit(0);
for (int t = 0; t < testcases; t++)
{
sb.append(br.readLine().toUpperCase()+"\n");
String s[]=br.readLine().split(" ");
int m=Integer.parseInt(s[0]);
int n=Integer.parseInt(s[1]);
int b=Integer.parseInt(s[2]);
if(m<1 || m>100 || n<1 || n>100 || b<1 || b>1000000)
break;
HashMap ingredientcost=new HashMap<>();
TreeSet recipes=new TreeSet<>(new Comparator()
{
@Override
public int compare(Recipe r1,Recipe r2)
{
if(r1.cost>r2.cost)
return 1;
else if(r1.cost==r2.cost)
return r1.name.compareTo(r2.name);
else
return -1;
}
});
for (int i = 0; i 100)
break;
int cost=0;
for (int j = 0; j < k; j++)
{
String s2[]=br.readLine().split(" ");
cost+=ingredientcost.get(s2[0])*Integer.parseInt(s2[1]);
}
//System.out.println("cost ="+cost);
r1.cost=cost;
recipes.add(r1);
}
boolean inbudget=false;
Iterator i=recipes.iterator();
while (i.hasNext())
{
Recipe recipe = (Recipe) i.next();
if(recipe.cost<=b)
{
inbudget=true;
sb.append(recipe.name+"\n");
}
}
if(!inbudget)
{
sb.append("Too expensive!\n");
}
sb.append("\n");
}
System.out.print(sb);
}
}
class Recipe
{
String name;
int cost;
public Recipe(String s)
{
name=s;
}
}
0 comments: