Union of Segments
Time limit1sMemory limit1024 MB
Given N segments with prices and lengths, answer Q queries: can a subset with total price A have a union length of exactly B?
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting, Intervals
- Solved
- No attempts yet
Problem
There are segments. The -th segment has price and length .
There are queries. For each query, determine whether you can choose a set of segments that satisfies the following condition.
- Choose a set of segments whose total price is exactly . Place the chosen segments on a one-dimensional number line, where segments may overlap. Can the length of the union of the segments be exactly ?
Input
The first line contains two integers and , separated by a space. (; )
The next lines each contain two integers and , separated by a space. (; )
The next lines each contain two integers and , separated by a space. (; )
Output
For each query, print YES if you can choose a set of segments that satisfies the condition, otherwise print NO. Print one answer per line, in the order the queries are given.