PivotOJ

Watering the Plants

시간 제한: 2000ms메모리 제한: 2048MB출처: USACO 2025 January PlatinumBOJ 33500

문제

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.

입력

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 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.

예제

예제 1

입력
3
39 69 33
30 29
출력
2070
2127

예제 2

입력
3
33 82 36
19 1
출력
1558
676

예제 3

입력
8
35 89 44 1 35 3 62 50
7 86 94 62 63 9 49
출력
623
4099
4114
6269
6272
6827
8827
코드를 제출하려면 로그인하세요.