#P9784. [ROIR 2020] 超速 (Day1)

[ROIR 2020] 超速 (Day1)

Description

Translated from ROIR 2020 Day1 T2. Превышение скорости, translated by ShineEternal.

Speeding is a dangerous illegal behavior that greatly increases the chance that traffic accidents lead to tragic consequences. Unfortunately, controlling speed using radar and cameras cannot completely solve the problem. To prevent this behavior, one can limit speeding by imposing fines based on the time a car spends on a section of road.

Now there are nn road segments numbered from 11 to nn. Segment ii has length lil_i meters, and its speed limit is viv_i meters per second. Speeding will be fined, but to reflect “pay according to work”, different levels of speeding have different fine amounts.

Specifically, if the car does not speed, then there is no fine. Otherwise, let ee be the value of the car’s maximum speed on this segment minus the speed limit:

  • If 0<ea10<e\leq a_1, the penalty is f1f_1 units of currency.
  • If a1<ea2a_1<e\leq a_2, the penalty is f2f_2 units of currency.
  • ...
  • If am2<eam1a_{m-2}<e\leq a_{m-1}, the penalty is fm1f_{m-1} units of currency.
  • If am1<ea_{m-1}<e, the penalty is fmf_m units of currency.

Currently, there are qq cars that will pass through these nn road segments. Each car arrives at segment 11 at time sis_i, and leaves segment nn at time tit_i.

You need to compute, for each car, the minimum possible value of the highest fine amount it is charged among all segments.

Time is measured starting from when the road opens, i.e. starting from 00.

Input Format

The first line contains a positive integer nn, the number of road segments.

The next two lines each contain nn numbers: the first line is viv_i, and the second line is lil_i.

The fourth line contains a positive integer mm, the number of the mm different fine ranges.

The next two lines: the first line contains m1m-1 numbers, which are aia_i; the second line contains mm numbers, which are fif_i.

The seventh line contains a positive integer qq, the number of cars.

The next qq lines each contain two integers si,tis_i,t_i.

Output Format

Output qq lines in total.

For each car, output the minimum fine amount it must be charged.

3
10 20 30
400 500 600
6
1 5 10 12 16
100 300 600 800 1000 1500
3
10 100
20 70
45 100
0
800
600

Hint

For 100%100\% of the testdata, 1n101\leq n\leq 10, 1vi,li,ai,fi1091\leq v_i,l_i,a_i,f_i\leq 10^9, 1m1051\leq m\leq 10^5, 1q1051\le q\le 10^5, 1si<ti1091\leq s_i<t_i\leq 10^9.

Task ID Special Constraints Score
11 n=1,m=1n=1,m=1 55
22 m=1m=1 1010
33 n=1,m10n=1,m\leq 10 99
44 n=1n=1 1212
55 m10,ai10m\leq 10,a_i\leq 10 1313
66 m10m\leq 10 1414
77 No special constraints 3737

Translated by ChatGPT 5