#P5861. [IOI 2015] teams
[IOI 2015] teams
Description
There are students in the class, numbered from to . Every day, the teacher has some projects that need to be completed by students. Each project must be completed within one day by a team of students. The projects may have different difficulty levels. For each project, the teacher knows how many students should be chosen to form a team to complete it.
Different students have different preferences for team size. More precisely, for student , they are only willing to work in a team whose size is between and (including and ). Each day, a student can be assigned to at most one team. Some students may not be assigned to any team. Each team is responsible for exactly one project.
The teacher has already selected the projects for each of the next days. For each day, you need to determine whether there exists an assignment of students such that every project has a team responsible for it.
Input Format
- Line contains a positive integer , the number of students in the class.
- Lines to each contain two integers , .
- Line contains a positive integer .
- Lines to each contain a positive integer , the number of projects to be completed that day, followed by a sequence of length . () denotes the required team size for project .
Output Format
Output lines. For each query, your program must output whether there exists a team assignment plan that can complete all projects of that day. If it is possible to form teams to complete all projects for that day, output 1; otherwise, output 0.
4
2 4
1 2
2 3
2 3
2
2 1 3
2 1 1
1
0
Hint
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号