Forming Teams
Time limit4sMemory limit512 MB
For each planned day, decide whether students with accepted size ranges can fill all requested teams of the given sizes.
- Level
Hard8 of 10
- Topics
- Greedy, Intervals, Sorting, Segment tree
- Solved
- No attempts yet
Problem
There are students numbered through . Every day the teacher prepares one or more projects, and each project is handled by one team that the students form on that day. Projects differ in difficulty, so the size of the team that handles a project is fixed in advance.
Students differ in the team sizes they accept. Student can join a team only if that team has at least and at most members. On a single day a student belongs to at most one team, and a student may belong to no team at all. One team handles exactly one project.
If a day has projects and the team for project must have size , then teams of sizes all have to exist on that day at the same time. The sum of the can exceed .
Teams are formed again from scratch every day, so the teams of one day do not restrict any other day. The teacher has already planned days. For each day, decide whether all the teams planned for that day can be formed.
Input
The first line contains the number of students . ()
Each of the next lines contains and separated by a space, in the order . ()
The next line contains the number of days . ()
Each of the next lines describes one day, in the planned order. A line contains the number of projects followed by the team sizes , with all numbers separated by spaces. (, )
The sum of over all days is at most .
Output
For each day, print if all the teams planned for that day can be formed, and otherwise. Print one answer per line, in the order the days are given.