Under construction

Still being built. Things may change

Apples into Baskets

Time limit2sMemory limit1024 MB

Summary
For each query, decide whether every pair (x, y) with x<=a and y<=b can be split between two baskets using apples of weight at most k.
Level

Hard8 of 10

Topics
Sorting, Prefix sum, Binary search
Solved
No attempts yet

Problem

Sasha has nn apples with integer weights w1,w2,…,wnw_1, w_2, \ldots, w_n, lying on a table. She also has two spacious baskets.

Sasha picks an integer kk and looks at the apples with weight at most kk. She may put each apple with wi≤kw_i \le k into one of the two baskets, or leave it on the table. Apples with wi>kw_i > k always stay on the table.

A pair of numbers (x,y)(x, y) is called kk-reachable if Sasha can put some apples of weight at most kk into the baskets so that the total weight in the first basket is xx and the total weight in the second basket is yy.

A pair (a,b)(a, b) is called kk-ideal if for every xx and yy with 0≤x≤a0 \le x \le a and 0≤y≤b0 \le y \le b, the pair (x,y)(x, y) is kk-reachable.

Sasha has qq triples of numbers kk, aa, bb. For each triple she wants to know whether the pair (a,b)(a, b) is kk-ideal.

Input

The first line contains two integers nn and qq, the number of apples and the number of queries (1≤n,q≤300 0001 \le n, q \le 300\,000).

The second line contains nn integers w1,w2,…,wnw_1, w_2, \dots, w_n, the weights of the apples (1≤wi≤10121 \le w_i \le 10^{12}).

The third line contains an integer zz, which is used to build the queries (0≤z≤1060 \le z \le 10^6).

Each of the next qq lines contains three integers jj, cc, dd (0≤j,c,d≤10180 \le j, c, d \le 10^{18}). Let vv be the sum of the numbers of the earlier queries whose pair (a,b)(a, b) was kk-ideal. The current query is then k=j−v⋅zk = j - v \cdot z, a=c−v⋅za = c - v \cdot z, b=d−v⋅zb = d - v \cdot z. It is guaranteed that k,a,b≥0k, a, b \ge 0.

If z=0z = 0 (which holds for most subtasks), then kk, aa, bb equal jj, cc, dd. In that case the query parameters do not depend on earlier answers and are given directly in the input.

Output

For each query, print Yes if the pair (a,b)(a, b) is kk-ideal, otherwise print No.

Examples2

  1. Example 1

    Input
    8 5
    17 1 3 2 100 5 6 1
    0
    6 15 3
    9 4 4
    5 15 3
    17 34 1
    16 33 2
    
    Expected output
    Yes
    No
    No
    Yes
    No
    
  2. Example 2

    Input
    8 5
    17 1 3 2 100 5 6 1
    1
    6 15 3
    10 5 5
    6 16 4
    18 35 2
    21 38 7
    
    Expected output
    Yes
    No
    No
    Yes
    No