Logo
(追記) (追記ここまで)

33081번 - Cooking Steaks 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB16111168.750%

문제

Morgan is a chef in a steak house. In his steak house, a steak can have $N$ level of doneness, numbered from 1ドル$ to $N$. Currently, Morgan has $A_i$ steaks of doneness level $i$ ready in his steak house.

There are $B_i$ orders of steaks with doneness level $i$ that need to be fulfilled. Morgan can cook the steaks in order to match the doneness level. For each 1ドル ≤ i < N,ドル it takes Morgan $T_i$ seconds to cook a steak from doneness level $i$ to $i + 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 $N$ (2ドル ≤ N ≤ 100,円 000$). The next line contains $N - 1$ integers $T_i$ (1ドル ≤ T_i ≤ 1000$) representing the time required to cook a steak of doneness level $i$ to $i+ 1$. The next line contains $N$ integers $A_i$ (0ドル ≤ A_i ≤ 1000$) representing the number of steaks with doneness level $i$. The next line contains $N$ integers $B_i$ (0ドル ≤ B_i ≤ 1000$) representing the number of orders for a steak with doneness level $i$.

출력

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.

제한

예제 입력 1

3
1 2
2 2 3
0 1 5

예제 출력 1

5

First, Morgan can cook both steaks with doneness level 2ドル$ to level 3ドル$ in 2ドル$ seconds each. Then, Morgan can cook one steak with doneness level 1ドル$ to level 2ドル$ in 1ドル$ second. Now, Morgan has 1ドル$ steak of doneness level 1ドル,ドル 1ドル$ steak of doneness level 2ドル,ドル and 5ドル$ steaks of doneness level 3ドル$. It is enough to fulfill all orders. There is no other way to fulfill all orders in less than 5ドル$ seconds.

예제 입력 2

3
1 2
2 2 3
1 2 1

예제 출력 2

0

The steaks ready in his steak house can fulfill all orders without any further cooking.

예제 입력 3

3
1 2
2 2 3
5 0 0

예제 출력 3

-1

It is impossible to have 5ドル$ steaks of doneness level 1ドル$.

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2022 B번

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2023 연습 세션 PB번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /