A Tree-Filled Tree Problem
Time limit2sMemory limit1024 MB
Given N lecture time intervals, find for each query the maximum number of non-overlapping lectures that includes the query's mandatory lectures.
- Level
Medium6 of 10
- Topics
- Intervals, Greedy, Binary search
- Solved
- No attempts yet
Problem
Jiho had to write a tree problem, but he had already written one that uses trees in its solution. So this time he decided to write a problem whose statement is full of trees.
To write a good problem whose statement is full of trees, he needs to take many tree lectures and learn a lot of tree-related knowledge. Luckily, Gyeonggi Science High School, which loves trees, has good tree lectures. The -th tree lecture runs from time to , and attending it gives unit of tree knowledge. If two tree lectures do not overlap in time, Jiho can attend both and study more about trees to write a better tree problem. Also, if or for two lectures, they count as overlapping.
Some of the tree lectures are mandatory, and Jiho can freely sign up for the rest as long as they do not overlap in time. Find the maximum amount of tree knowledge Jiho can obtain.
Jiho does not yet know which tree lectures are mandatory. For each of the queries, a few mandatory tree lectures are given. For each query, print the maximum amount of tree knowledge Jiho can obtain.
Input
The first line contains and , separated by a space.
From the second line onward, the -th of the next lines contains two integers and , separated by a space, which are the start and end times of the -th tree lecture.
The following lines each contain one query. Each query gives the number of mandatory tree lectures, followed by the lecture numbers , all separated by spaces.
Output
Print lines. The -th line contains the maximum amount of tree knowledge Jiho can obtain for the -th query.
Constraints
- ()
- (The sum of over all queries)
- In each query, ()
- In each query,
Hint
Two different tree lectures may start and end at exactly the same time.
The word "tree" appears 36 times in this statement (38 times including the title).