Cooking Steaks

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

요약
각 익힘 정도마다 있는 스테이크 수와 주문 수가 주어질 때, 한 번에 하나만 조리하는 조건에서 모든 주문을 처리하는 최소 총 조리 시간을 구하거나 불가능하면 -1을 출력한다.
난이도

보통10점 중 6점

유형
그리디, 시뮬레이션, 누적 합
정답자
아직 제출이 없습니다

문제

Morgan is a chef in a steak house. In his steak house, a steak can have NN level of doneness, numbered from 11 to NN. Currently, Morgan has A_iA\_i steaks of doneness level ii ready in his steak house.

There are B_iB\_i orders of steaks with doneness level ii that need to be fulfilled. Morgan can cook the steaks in order to match the doneness level. For each 1≤i<N1 ≤ i < N, it takes Morgan T_iT\_i seconds to cook a steak from doneness level ii to i+1i + 1. Note that Morgan can only cook one steak at a time.

Morgan asks for your help to find the minimum total time to fulfil all orders, or tell him that the orders are impossible to fulfil.

입력

Input begins with an integer NN (2≤N≤100,0002 ≤ N ≤ 100\\, 000). The next line contains N−1N - 1 integers T_iT\_i (1≤T_i≤10001 ≤ T\_i ≤ 1000) representing the time required to cook a steak of doneness level ii to i+1i+ 1. The next line contains NN integers A_iA\_i (0≤A_i≤10000 ≤ A\_i ≤ 1000) representing the number of steaks with doneness level ii. The next line contains NN integers B_iB\_i (0≤B_i≤10000 ≤ B\_i ≤ 1000) representing the number of orders for a steak with doneness level ii.

출력

If all orders can be fulfilled, then output an integer in a single line representing the minimum total time to fulfill all orders. Otherwise, output -1 in a single line.

예제3

  1. 예제 1

    입력
    3
    1 2
    2 2 3
    0 1 5
    
    예상 출력
    5
    
  2. 예제 2

    입력
    3
    1 2
    2 2 3
    1 2 1
    
    예상 출력
    0
    
  3. 예제 3

    입력
    3
    1 2
    2 2 3
    5 0 0
    
    예상 출력
    -1