|
|||
I — Doing HomeworkIgnatius has just come back to school from the 30th ACM ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test, 1 point for 1 day. As you know, doing homework always takes a long time. So Ignatius wants you to help him determine an ordering of his homework assignments that will minimize the reduced score. Input SpecificationThe input contains several test cases. The first line of the input consists of a single integer T, which is the number of test cases. T test cases follow. Each test case starts with a positive integer N (1 ≤ N ≤ 15), indicating the number of homework assignments. Then N lines follow. Each line contains a string S (the subject's name, having at most 100 characters) and two integers D (the deadline of the subject's homework in days) and C (the number of days it takes Ignatius to finish this subject's homework). Note: All subject names are given in alphabetically ascending order, so you can process the problem much easier. Output SpecificationFor each test case, output the lowest total reduced score, then print the ordering of the subjects, one subject per line. If there is more than one ordering, output the alphabetically first one. Sample Input
Output for Sample Input
HintIn the second test case, both Computer→English→Math and Computer→Math→English leads to a 3-point reduction, but the word “English” appears earlier than the word “Math”, so we choose the first ordering. This will result in the alphabetically first ordering. |
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |