Watering the Plants

시간 제한2초메모리 제한2048 MB

요약
각 식물 접두사마다 그 안의 수로만 써서 모든 식물의 물 요구량을 채우는 최소 비용을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 그리디, 구현, 누적 합
정답자
아직 제출이 없습니다

문제

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 w_iw\_i (0≤w_i≤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 c_ic\_i (1≤c_i≤1061\le c\_i\le 10^6), such that Bessie can pay c_ikc\_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.

입력

The first line contains a single positive integer NN.

The second line contains NN space-separated integers w_1,…,w_Nw\_1, \ldots, w\_N.

The third line contains N−1N-1 space-separated integers c_1,…,c_N−1c\_1, \ldots, c\_{N-1}.

출력

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

  1. 예제 1

    입력
    3
    39 69 33
    30 29
    
    예상 출력
    2070
    2127
    
  2. 예제 2

    입력
    3
    33 82 36
    19 1
    
    예상 출력
    1558
    676
    
  3. 예제 3

    입력
    8
    35 89 44 1 35 3 62 50
    7 86 94 62 63 9 49
    
    예상 출력
    623
    4099
    4114
    6269
    6272
    6827
    8827