Assembling a Computer
Time limit1sMemory limit128 MB
Choose one part per category within a budget to maximize the minimum quality among chosen parts, typically via binary search plus greedy cheapest-part selection.
- Level
Medium6 of 10
- Topics
- Binary search, Greedy, Implementation
- Solved
- No attempts yet
Problem
Sang-geun decided to build a new computer himself. To complete it, he must buy exactly one part of every type that appears in the input.
The overall performance of the computer equals the performance of its worst part (the one with the lowest performance). Without exceeding a given budget, Sang-geun wants to maximize this "performance of the worst part".
Given the type, name, price, and performance of every available part, write a program that computes the maximum performance of a computer he can assemble within the budget.
Input
The first line contains the number of test cases, which is at most 100.
The first line of each test case contains the number of parts and the budget . (, )
Each of the next lines describes one part in the format type name price quality, where type is the part's category, name is its name, price is its cost (), and quality is its performance ().
All part names are distinct, and a larger quality value means better performance. Every string consists only of letters, digits, and underscores (_) and has length at most 20.
To assemble a computer, exactly one part must be chosen for every type that appears in the input. Every input is guaranteed to allow assembling a computer within the given budget.
Output
For each test case, print on its own line the maximum performance of a computer that can be assembled within the budget.