Component Testing
Time limit20sMemory limit128 MB
Given component classes each needing a set number of distinct reviewers per component, and engineer ranks each able to review a limited number of components, decide if all components can be reviewed.
- Level
Medium7 of 10
- Topics
- Greedy, Sorting, Math, Implementation
- Solved
- No attempts yet
Problem
The engineers at INU Electronics have developed some new electronic components, and over the next two months they plan to thoroughly review and test them.
Each component is sorted into one of several classes according to its complexity and importance. Every component in the same class needs the same number of reviewers, while different classes may need different numbers of reviewers. A single class may contain many components. The reviewers of any one component must all be distinct (the same engineer cannot review a single component twice).
INU Electronics has several ranks. Each engineer holds exactly one rank, and all engineers of the same rank can review the same maximum number of components. Every engineer is able to review any component. An engineer may review several components of the same class or components of different classes, but may never review the same component more than once.
Determine whether all of the components can be tested within two months.
Input
The input consists of several test cases.
The first line of each test case contains two integers () and (), where is the number of component classes and is the number of engineer ranks.
Each of the next lines describes one class with two integers () and (): is the number of components in that class, and is the number of distinct reviewers required to review each component of that class.
Each of the next lines describes one rank with two integers () and (): is the number of engineers holding that rank, and is the maximum number of components a single engineer of that rank can review.
The input ends with a line containing two zeros.
Output
For each test case, print on its own line if every component can be reviewed, and otherwise.