2016 ACM ICPC Asia Nha Trang Regional Contest Replay


2017-10-15 12:00 UTC

2016 ACM ICPC Asia Nha Trang Regional Contest Replay


2017-10-15 17:00 UTC
The end is near!
Contest is over.
Not yet started.
Contest is starting in -611 days 21:30:04

Time elapsed


Time remaining


Problem B

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:

\includegraphics[width=0.3\textwidth ]{1.jpg}

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.


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})$.


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

\includegraphics[width=0.3\textwidth ]{2.jpg} \includegraphics[width=0.3\textwidth ]{3.jpg} \includegraphics[width=0.3\textwidth ]{4.jpg}

Sample Input 1 Sample Output 1
1 3 5 8
2 5 3 1