#P4602. [CTSC2018] 混合果汁

    ID: 3450 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2018线段树WC/CTSC/集训队O2优化可持久化整体二分

[CTSC2018] 混合果汁

Description

Little R is obsessed with making “dark cuisine”, especially mixed juice.

There are nn kinds of juice in the store, numbered 0,1,,n10,1,\cdots,n-1. The deliciousness of juice ii is did_i, and its price per liter is pip_i. When making mixed juice, Little R also has some special rules: in a bottle of mixed juice, juice ii can be added at most lil_i liters.

Now mm children come to Little R for mixed juice. They all want Little R to use the juices in the store to make a bottle of mixed juice for them. For the jj-th child, they want the total price of the mixed juice to be no more than gjg_j, and the volume to be at least LjL_j. Under these constraints, the children also hope the deliciousness of the mixed juice is as high as possible. The deliciousness of a bottle of mixed juice equals the minimum deliciousness among all juices that participate in the mixture. Please compute the highest deliciousness each child can get.

Input Format

The first line contains two positive integers n,mn, m, the number of kinds of juice and the number of children.

The next nn lines each contain three positive integers di,pi,lid_i, p_i, l_i, meaning the deliciousness of juice ii is did_i, its price per liter is pip_i, and its addition limit in one bottle is lil_i liters.

The next mm lines describe all children: each line contains two positive integers gj,Ljg_j, L_j, meaning the jj-th child can pay at most gjg_j yuan, and wants at least LjL_j liters of juice.

Output Format

For all children in order, output one line for each child containing an integer, the highest deliciousness of the mixed juice they can drink. If their request cannot be satisfied, output 1-1.

3 4
1 3 5
2 1 3
3 2 5
6 3
5 3
10 10
20 10
3
2
-1
1

Hint

For all testdata, it is guaranteed that n,m100000n, m \le 100000, 1di,pi,li1051 \le d_i,p_i,l_i \le 10^5, 1gj,Lj10181 \le g_j, L_j \le 10^{18}.

测试点编号 n=n= m=m= 其他限制
1,2,31,2,3 1010 None
4,5,64,5,6 500500
7,8,97,8,9 50005000
10,11,1210,11,12 100000100000 pi=1p_i=1
13,14,1513,14,15 li=1l_i=1
16,17,18,19,2016,17,18,19,20 None

Translated by ChatGPT 5