#P10769. 「CROI · R2」公交接驳

    ID: 9811 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp贪心洛谷原创O2优化分治四边形不等式洛谷月赛

「CROI · R2」公交接驳

Description

To handle peak-hour crowds, the bus company will deploy kk buses along a route with nn transfer stations (numbered 1 to nn west-to-east). Each transfer station ii has a priority value viv_i. The travel time from station ii to i+1i+1 is sis_i (ignoring stop time). The railway arrives at station ii at time tit_i. Bus travel time between stations is always ≥ railway travel time.

You must schedule kk buses such that:

  1. All passengers arriving at any station ii at tit_i can board a bus (bus arrival time ≥ tit_i).
  2. For each station ii, the dissatisfaction is calculated as:
    (waiting time for the first bus) × (priority vjv_j of the bus's origin station).
    If multiple buses arrive simultaneously, passengers choose the one with the smallest vjv_j.

Minimize the total dissatisfaction across all stations for multiple queries with different tit_i and kk.

Input Format

First line: Integer nn (number of stations).
Second line: n1n-1 integers s1,...,sn1s_1,...,s_{n-1} (travel times).
Third line: nn integers v1,...,vnv_1,...,v_n (priorities).
Fourth line: Integer pp (number of railway schedules).

For each schedule:

  • Line 1: nn integers t1,...,tnt_1,...,t_n (railway arrival times).
  • Line 2: Integer qiq_i (number of queries).
  • Line 3: qiq_i integers k1,...,kqik_1,...,k_{q_i} (bus counts to test).

Output Format

For each schedule, output qiq_i integers—the minimal total dissatisfaction for each kk.

3
3 4
6 2 1
2
1 3 7
2
1 2
2 3 5
3
1 2 4

12 0
36 4 0
6
2 2 2 2 3
13 12 15 9 3 1
3
5 7 9 11 12 13
4
1 2 4 8
3 4 5 7 8 10
3
2 4 5
1000000 1000001 1000002 1000003 1000004 1000005
2
1 3

52 6 0 0
49 3 0
208 31

Hint

【Data Range】
Constraints:

  • 1n10001 \leq n \leq 1000, 1p101 \leq p \leq 10
  • siti+1ti0s_i \geq t_{i+1} - t_i \geq 0
  • 1qi,ki1061 \leq q_i, k_i \leq 10^6, 0vi,si1060 \leq v_i, \sum s_i \leq 10^6, 1ti2×1061 \leq t_i \leq 2 \times 10^6

Subtasks:
| Subtask | nn | qq | kik_i | si\sum s_i | Special | Points | |---------|-----|-----|-------|------------|---------|--------| | 1 | 15 | 1e3 | 1e3 | 15 | None | 5 | | 2 | 15 | 1e6 | 1e6 | 1e6 | None | 5 | | 3 | 100 | 1e6 | 1e6 | 1e6 | None | 15 | | 4 | 1e3 | 1e6 | 1e6 | 1e6 | A | 5 | | 5 | 1e3 | 1e6 | 1e6 | 1e6 | B | 30 | | 6 | 1e3 | 1e3 | 1.1e3 | 1e3 | None | 10 | | 7 | 1e3 | 1e6 | 1e6 | 1e6 | None | 30 |

  • Special A: si=ti+1tis_i = t_{i+1} - t_i
  • Special B: vi=1v_i = 1

【Sample Explanation】
Below are feasible optimal bus scheduling plans for the sample queries. Note that there may be multiple valid optimal solutions.

For the first schedule in Sample 1:

  • When k=1 k=1 :
    A bus departs station 1 at time 1 1 . Operational details:
    | | Station 1 | Station 2 | Station 3 |
    | :-------------------: | :-------: | :-------: | :-------: |
    | Railway Arrival Time | 1 1 | 3 3 | 7 7 |
    | Bus Service 1 Arrival | 1 1 | 4 4 | 8 8 |
    | Boarded Service | Service 1 | Service 1 | Service 1 |
    | Waiting Time | 0 0 | 1 1 | 1 1 |

    Service 1 starts at station 1 (v1=6 v_1=6 ). Total dissatisfaction:

    6×0+6×1+6×1=126 \times 0 + 6 \times 1 + 6 \times 1 = 12
  • When k=2 k=2 :
    Buses depart station 1 at t=1 t=1 and station 2 at t=3 t=3 . Operational details:
    | | Station 1 | Station 2 | Station 3 |
    | :-------------------: | :-------: | :-------: | :-------: |
    | Railway Arrival Time | 1 1 | 3 3 | 7 7 |
    | Bus Service 1 Arrival | 1 1 | 4 4 | 8 8 |
    | Bus Service 2 Arrival | — | 3 3 | 7 7 |
    | Boarded Service | Service 1 | Service 2 | Service 2 |
    | Waiting Time | 0 0 | 0 0 | 0 0 |

    Service 1 starts at station 1 (v1=6 v_1=6 ), Service 2 at station 2 (v2=2 v_2=2 ). Total dissatisfaction:

    6×0+2×0+2×0=06 \times 0 + 2 \times 0 + 2 \times 0 = 0

For the second schedule in Sample 1:

  • When k=1 k=1 :
    A bus departs station 1 at t=2 t=2 . Operational details:
    | | Station 1 | Station 2 | Station 3 |
    | :-------------------: | :-------: | :-------: | :-------: |
    | Railway Arrival Time | 2 2 | 3 3 | 5 5 |
    | Bus Service 1 Arrival | 2 2 | 5 5 | 9 9 |
    | Boarded Service | Service 1 | Service 1 | Service 1 |
    | Waiting Time | 0 0 | 2 2 | 4 4 |

    Total dissatisfaction:

    6×0+6×2+6×4=366 \times 0 + 6 \times 2 + 6 \times 4 = 36
  • When k=2 k=2 :
    Buses depart station 1 at t=2 t=2 and station 2 at t=3 t=3 . Operational details:
    | | Station 1 | Station 2 | Station 3 |
    | :-------------------: | :-------: | :-------: | :-------: |
    | Railway Arrival Time | 2 2 | 3 3 | 5 5 |
    | Bus Service 1 Arrival | 2 2 | 5 5 | 9 9 |
    | Bus Service 2 Arrival | — | 3 3 | 7 7 |
    | Boarded Service | Service 1 | Service 2 | Service 2 |
    | Waiting Time | 0 0 | 0 0 | 2 2 |

    Total dissatisfaction:

    6×0+2×0+2×2=46 \times 0 + 2 \times 0 + 2 \times 2 = 4
  • When k=4 k=4 :
    Buses depart:

    • Station 1 at t=2 t=-2 and t=2 t=2 .
    • Station 2 at t=1 t=1 and t=3 t=3 .
      Operational details:
    Station 1 Station 2 Station 3
    Railway Arrival Time 2 2 3 3 5 5
    Bus Service 1 Arrival 2-2 1 1
    Bus Service 2 Arrival 2 2 5 5 9 9
    Bus Service 3 Arrival - 1 1 5 5
    Bus Service 4 Arrival 3 3 7 7
    Boarded Service Service 2 Service 4 Service 3
    Waiting Time 0 0

    Services 1/2 start at station 1 (v1=6 v_1=6 ), Services 3/4 at station 2 (v2=2 v_2=2 ). Total dissatisfaction:

    6×0+2×0+2×0=06 \times 0 + 2 \times 0 + 2 \times 0 = 0

    Note: At Station 3, Services 1 and 3 arrive simultaneously at t=5 t=5 . Passengers choose Service 3 (lower vj=2 v_j=2 ) over Service 1 (vj=6 v_j=6 ).