Civilization
Time limit1sMemory limit256 MB
Pick the smallest subset of at most 18 regions whose total workforce, tax income, and farm count all reach the required thresholds, or print game over.
- Level
Medium4 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
Emperor Montezuma of the Aztec civilization has a hard time planning the output of his capital city. The city is divided into square regions of equal size, and each region has three important values: the workforce, meaning the number of people able to work, the tax income Montezuma collects from the region, given in Quetzal, the Aztec currency, and the number of farms.
A region contributes to the city only if an administrator is assigned to it. A region without an administrator stays self sufficient and is not counted as part of the city. Montezuma collects no taxes there, cannot use its workforce, and cannot use the food its farms produce.
Montezuma wants his capital to be prosperous while using as few administrators as possible. The city is prosperous when the total workforce, the total tax income and the total number of farms over the administered regions are each at least the given threshold.
Montezuma had no computer. You read about him in the encyclopedia of the computer game Civilization, so you decided to write a program that computes the fewest regions Montezuma has to administer for the city to reach the workforce, tax and farm thresholds at the same time.
Input
The first line contains the number of test cases .
The first line of each test case contains the number of regions near the capital, . The next line contains the workforce , the tax income and the number of farms that the city needs to be prosperous, separated by spaces. Each of the next lines contains the workforce , the tax income and the number of farms that region offers.
Output
For each test case, print on one line the minimum number of regions that need an administrator. If no choice of regions makes the city prosperous, print game over instead.