Under construction

Still being built. Things may change

Union of Segments

Time limit1sMemory limit1024 MB

Summary
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 NN segments. The ii-th segment has price PiP_i and length LiL_i.

There are QQ 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 AjA_j. 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 BjB_j?

Input

The first line contains two integers NN and QQ, separated by a space. (1≤N≤1001 \le N \le 100; 1≤Q≤200 0001 \le Q \le 200\,000)

The next NN lines each contain two integers PiP_i and LiL_i, separated by a space. (1≤Pi≤10 0001 \le P_i \le 10\,000; 1≤Li≤10 0001 \le L_i \le 10\,000)

The next QQ lines each contain two integers AjA_j and BjB_j, separated by a space. (1≤Aj≤1061 \le A_j \le 10^6; 1≤Bj≤1061 \le B_j \le 10^6)

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.

Examples1

  1. Example 1

    Input
    3 4
    3 8
    5 10
    7 11
    8 15
    5 10
    16 20
    12 7
    
    Expected output
    YES
    YES
    NO
    NO