Protective masks
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk wants to visit \(n\) stores in a given order. To enter a store, he must have a protective mask.
At the entrance to the \(i\)-th store, disposable masks are sold at a price of \(a_i\) and reusable ones at a price of \(b_i\). Zenyk will buy no more than one mask at the entrance to the \(i\)-th store. If he buys a disposable one, he will use it only in this store and then dispose of it. A reusable mask can be used in all subsequent stores.
You need to tell the minimum amount of money Zenyk will spend on masks.
Input
The first line contains an integer \(n\) — the number of stores Zenyk must visit.
The second line contains \(n\) integers \(a_i\) — the prices of disposable masks in hryvnias.
The third line contains \(n\) integers \(b_i\) — the prices of reusable masks in hryvnias.
Output
In a single line, print an integer — the minimum amount of money Zenyk will spend on masks (in hryvnias).
Constraints
\(1 \le n \le 10^5\),
\(1 \le a_i, b_i \le 10^9\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 7 10 12 15 11 9 8 16 100 200 150 40 47 60 74 | 77 |
| Input (stdin) | Output (stdout) |
|---|---|
| 7 10 12 15 11 9 8 16 100 200 150 50 47 60 74 | 81 |
Notes
In the first example, it is profitable for Zenyk to buy disposable masks in the first three stores and a reusable one in the fourth store. Then he will have to pay \(10+12+15+40=77\) (uah).
In the second example, it is profitable to buy disposable masks in all stores.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|