This page is still under construction.

Parts of this page are still being built. What you see may change.

Chocolate River Flow and Temperature

Time limit2sMemory limit1024 MB

Summary
For each query temperature and total flow, decide whether some choice of flows within each tap's range produces that exact weighted-average temperature and total.
Level

Medium7 of 10

Topics
Math, Greedy, Geometry, Binary search
Solved
No attempts yet

Problem

Having recently taken over the Wonka Factory, Charlie is now in charge of the day-to-day production of the various chocolate products made there. While this may seem like a cushy job with an all-you-can-eat-chocolate perk, it also comes with the difficult responsibility of keeping the (somewhat convoluted and complicated) production lines working.

The heart of the factory is the Chocolate River, where raw molten chocolate flows from kk chocolate-producing faucets to outlets where different types of pralines and chocolate bars are made. The ii'th of the kk chocolate faucets produces chocolate at some fixed temperature tit_i, and the amount of chocolate flowing from the faucet can be adjusted to any value between aia_i and bib_i millilitres per second. Suppose the kk taps are adjusted to produce x1,x2,…,xkx_1, x_2, \ldots, x_k millilitres of chocolate per second respectively (where ai≤xi≤bia_i \le x_i \le b_i). Then the total flow in the Chocolate River is x1+x2+…+xkx_1 + x_2 + \ldots + x_k, and its temperature is the weighted average

[ \frac{x_1 t_1 + x_2t_2 + \ldots + x_kt_k}{x_1 + x_2 + \ldots + x_k} ]

(each faucet produces grade A quality chocolate which instantly mixes with the chocolate from the other faucets).

Each type of praline and chocolate bar produced at the factory requires the Chocolate River to be adjusted to have a specific temperature and flow level. Charlie recently came across a long list of new praline recipes, and would now like to figure out which of these are even possible to make at the factory. Write a program to determine, for each of the new recipes, if its required temperature and flow level is possible to achieve with some setting of the kk faucets.

Input

The first line of input contains an integer kk (1≤k≤101 \le k \le 10), the number of taps. Then follow kk lines, describing the taps. The ii'th of these lines contains the three integers tit_i, aia_i, and bib_i (0≤ti≤1060 \le t_i \le 10^6, 0≤ai≤bi≤1060 \le a_i \le b_i \le 10^6) describing the ii'th faucet.

Next follows a line containing an integer rr (1≤r≤1051 \le r \le 10^5), the number of new recipes to check. Then follows rr lines, each describing a recipe. A recipe is described by two integers τ\tau and ϕ\phi (0≤τ≤1060 \le \tau \le 10^6 and 1≤ϕ≤1061 \le \phi \le 10^6), where τ\tau is the chocolate temperature and ϕ\phi the chocolate flow needed for this recipe.

Output

For each of the rr recipes, print one line with the string "yes" if it is possible to achieve the desired combination of chocolate temperature and flow, and "no" otherwise.

Examples1

  1. Example 1

    Input
    2
    50 0 100
    100 50 100
    3
    20 75
    75 150
    75 90
    
    Expected output
    no
    yes
    no