시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB75571.429%

문제

Peter is going to buy a truck and start a small transportation business. He studied the market and found out that there are $n$ potential customers in his city. There are $m_i$ contract options for the $i$-th client. Each option is specified by two numbers: $w_{ij}$ --- the minimum capacity of the truck, which is required to fulfill the contract, and $c_{ij}$ --- the profit that Peter will receive if he concludes this contract. No more than one contract can be concluded with each client.

Now Peter is thinking which truck is better to buy in order to get the profit he needs. He has $q$ options. In the $i$-th option, Peter wants his profit to be at least $x_i$. Help him, for each of the options, find the minimum capacity of the truck with which you can make such a profit.

입력

The first line contains the integer $n$ ($1\le n\le 10^5$).

This is followed by $n$ blocks describing contract options for each of the potential customers. Each such block begins with the number $m_i$, followed by $m_i$ pairs of numbers $w_{ij}, c_{ij}$ ($1\le m_i$, $\sum m_i \le 5 \cdot 10^5$, $1\le w_{ij}, c_{ij}\le 10^9$).

Next comes the number $q$ ($1\le q\le 10^5$). This is followed by the $q$ numbers $x_i$ ($1\le x_i\le 10^9$).

출력

Print $q$ numbers, the minimum carrying capacity of the truck, with which you can get the required profit, for each of the options. If it is impossible to get the required profit, print $-1$ for the corresponding option.

서브태스크

번호배점제한
17

$n \le 5$, $\sum m_i \le 10$, $q \le 10$, $w_i, c_i, x_i \le 100$

215

$n \le 100$, $\sum m_i \le 500$, $q \le 10$, $w_i, c_i, x_i \le 100$

321

$n \le 10^5$, $\sum m_i \le 5 \cdot 10^5$, $q \le 10$

424

$n \le 10^5$, $\sum m_i \le 5 \cdot 10^5$, $q \le 10^5$, $w_i \le 100$

533

$n \le 10^5$, $\sum m_i \le 5 \cdot 10^5$, $q \le 10^5$

예제 입력 1

3
2
10 20
20 30
1
40 50
3
2 5
1 10
4 7
5
10 55 32 100 17

예제 출력 1

1 40 20 -1 10

채점 및 기타 정보

  • 예제는 채점하지 않는다.