#P11678. [USACO25JAN] Watering the Plants P

[USACO25JAN] Watering the Plants P

Problem Description

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

Bessie has a very peculiar irrigation system with N−1N-1 canals, numbered 11 through N−1N-1. Each canal ii has an associated unit cost cic_i (1≤ci≤1061\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 2≤i≤N2\leq i \leq N compute the minimum cost required to water plants 11 through ii using only the first i−1i-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 N−1N-1 space-separated integers c1,…,cN−1c_1, \ldots, c_{N-1}.

Output Format

Output N−1N-1 newline-separated integers. The (i−1)(i-1)th integer should contain the minimum cost to water the first ii plants using the first i−1i-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 30⋅69=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 39⋅30+29⋅33=212739 \cdot 30 + 29 \cdot 33 = 2127.

SCORING:

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