#C10949. Maximize Array Sum Under Operation Constraints

    ID: 40210 Type: Default 1000ms 256MiB

Maximize Array Sum Under Operation Constraints

Maximize Array Sum Under Operation Constraints

You are given three arrays of length n: arr, ops, and B. The array arr contains initial integer values. For each index i, you are allowed to increase arr[i] by at most ops[i], but the resulting value cannot exceed the upper bound given by B[i]. Your task is to compute the maximum possible sum of the array after applying these operations optimally.

Input Format: The first line contains an integer n. The next line contains n space-separated integers representing arr. The following line contains n space-separated integers representing ops. The last line contains n space-separated integers representing B.

Output Format: Output a single integer which is the maximum sum obtainable after applying the operations with the constraint that no element exceeds its corresponding upper bound.

Note: In mathematical terms, for each index i the new value is:

ai=min(ai+opsi,Bi)a_i' = \min(a_i + ops_i, B_i)

and the answer is:

answer=i=1nai\text{answer} = \sum_{i=1}^{n} a_i'

inputFormat

The first line contains an integer n, the number of elements in each array.

The second line contains n space-separated integers representing the elements of arr.

The third line contains n space-separated integers representing the number of operations allowed for each element (ops).

The fourth line contains n space-separated integers representing the upper bounds for each element (B).

outputFormat

Output a single integer which is the maximum possible sum of the array after applying the operations without exceeding the upper bounds.

## sample
4
1 2 3 4
3 3 3 3
7 8 6 5
20