 2016 ACM ICPC Asia Nha Trang Regional Contest Replay

#### Start

2017-10-15 04:00 AKDT

## 2016 ACM ICPC Asia Nha Trang Regional Contest Replay

#### End

2017-10-15 09:00 AKDT
The end is near!
Contest is over.
Not yet started.
Contest is starting in -1106 days 10:32:30

5:00:00

0:00:00

# Problem BReservoir

A big reservoir was built on Red River using a dam. Assume that the reservoir is a rectangular box with unit length width. The reservoir consists of many tanks. An example a cross section of an empty reservoir along its length and height dimensions is shown in the picture below: Water flows in from the top left gate into the reservoir. The tanks in the reservoir are constructed using walls. Each wall is one unit thick (along the width dimension) and is shorter than the height of the reservoir.

Given the locations and the heights of the walls and the unit volume $K$ of water flowing in, your task is to figure out the last wall water flows over.

## Input

The input consists of several datasets. The first line of the input contains the number of datasets, which is a positive number and is not greater than $20$. The following lines describe the datasets.

Each dataset is described by the following lines:

• The first line contains one positive integers $N$ – the number of walls separating the tanks $(N \leq {10}^{5})$

• The second line contains $N$ positive integers ${L}_{i}$ – the horizontal location (along the length dimension of the reservoir) of the ${i}^\textrm {th}$ wall $(1 \leq {L}_{i} \leq {10}^{9}, {L}_{i} > {L}_{i-1} + 1$ for $i > 1)$.

• The third line contains $N$ positive integers ${H}_{i}$ – the height in unit length of the ${i}^\textrm {th}$ wall $(1 \leq {H}_{i} \leq {10}^{5})$.

• The fourth line contains an integer $Q$ – the number of queries $(1 \leq Q \leq {10}^{5})$.

• In the next $Q$ lines, each line contains a positive integer $K$ that is the unit volume of water flowing in the reservoir $(1 \leq K \leq {10}^{15})$.

## Output

For each dataset, output $Q$ lines where the ${i}^\textrm {th}$ contains the index of the last wall that water flows over for the ${i}^\textrm {th}$ query. If there is no wall that water flows over, output $0$.

## Explanation for the Sample Dataset   Sample Input 1 Sample Output 1
1
4
1 3 5 8
2 5 3 1
3
3
13
17

1
1
3