#P11678. [USACO25JAN] Watering the Plants P

[USACO25JAN] Watering the Plants P

Description

Bessie's garden has NN plants labeled 11 through NN (2N51052\leq N\leq 5\cdot 10^5) from left to right. Bessie knows that plant ii requires at least wiw_i (0wi1060\leq w_i \leq 10^6) units of water.

Bessie has a very peculiar irrigation system with N1N-1 canals, numbered 11 through N1N-1. Each canal ii has an associated unit cost cic_i (1ci1061\le c_i\le 10^6), such that Bessie can pay cikc_i k to provide plants ii and i+1i+1 each with kk units of water, where kk is a non-negative integer.

Bessie is busy and may not have time to use all the canals. For each 2iN2\leq i \leq N compute the minimum cost required to water plants 11 through ii using only the first i1i-1 canals.

Input Format

The first line contains a single positive integer NN.

The second line contains NN space-separated integers w1,,wNw_1, \ldots, w_N.

The third line contains N1N-1 space-separated integers c1,,cN1c_1, \ldots, c_{N-1}.

Output Format

Output N1N-1 newline-separated integers. The (i1)(i-1)th integer should contain the minimum cost to water the first ii plants using the first i1i-1 canals.

3
39 69 33
30 29
2070
2127
3
33 82 36
19 1
1558
676
8
35 89 44 1 35 3 62 50
7 86 94 62 63 9 49
623
4099
4114
6269
6272
6827
8827

Hint

For Sample 1:

The minimum cost to water the first 22 plants using the first canal is to pay 3069=207030 \cdot 69 = 2070 by using the first canal 6969 times.

The minimum cost to water the first 33 plants is to use the first canal 3939 times and the second canal 3333 times, paying 3930+2933=212739 \cdot 30 + 29 \cdot 33 = 2127.

SCORING:

  • Input 4: N200N \leq 200, and all wi200w_i \leq 200.
  • Inputs 5-6: All wi200w_i \leq 200.
  • Inputs 7-10: N5000N \leq 5000.
  • Inputs 11-14: All wiw_i and cic_i are generated independently and uniformly at random.
  • Inputs 15-19: No additional constraints.