Apples into Baskets
Time limit2sMemory limit1024 MB
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 apples with integer weights , lying on a table. She also has two spacious baskets.
Sasha picks an integer and looks at the apples with weight at most . She may put each apple with into one of the two baskets, or leave it on the table. Apples with always stay on the table.
A pair of numbers is called -reachable if Sasha can put some apples of weight at most into the baskets so that the total weight in the first basket is and the total weight in the second basket is .
A pair is called -ideal if for every and with and , the pair is -reachable.
Sasha has triples of numbers , , . For each triple she wants to know whether the pair is -ideal.
Input
The first line contains two integers and , the number of apples and the number of queries ().
The second line contains integers , the weights of the apples ().
The third line contains an integer , which is used to build the queries ().
Each of the next lines contains three integers , , (). Let be the sum of the numbers of the earlier queries whose pair was -ideal. The current query is then , , . It is guaranteed that .
If (which holds for most subtasks), then , , equal , , . 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 is -ideal, otherwise print No.