Блог пользователя siriexo

Автор siriexo, 19 часов назад, По-английски

I recently came up with this problem, I'd really appreciate feedback from experienced problem setters and contestants, any attempt to break this problem, simplify it, or find flaws in the intended solution:

THIS IS STILL ONLY A PROBLEM IDEA WITH A PROPOSED SOLUTION SKETCH AND MAY OR MAY NOT HAVE 998244353 FLAWS

Prefix-Suffix Levelling

Statement

You are given an array $$$A$$$ of $$$N$$$ integers, and two positive cost arrays $$$P$$$ and $$$S$$$ of size $$$N$$$.

In one step, you can choose an index $$$i$$$ ($$$1 \le i \le N$$$) and perform one of the following two operations: 1. Prefix Addition: Add $$$+1$$$ to all elements in the prefix $$$A[1 \dots i]$$$, paying a cost of $$$P_i$$$. 2. Suffix Addition: Add $$$+1$$$ to all elements in the suffix $$$A[i \dots N]$$$, paying a cost of $$$S_i$$$.

Find the minimum total cost to make all elements of $$$A$$$ non-negative ($$$A_k \ge 0$$$ for all $$$1 \le k \le N$$$).


Input Format

The first line contains a single integer $$$N$$$ ($$$1 \le N \le 5 \cdot 10^5$$$) — the size of the arrays.

The second line contains $$$N$$$ integers $$$A_1, A_2, \dots, A_N$$$ ($$$-10^9 \le A_i \le 10^9$$$) — the initial array values.

The third line contains $$$N$$$ integers $$$P_1, P_2, \dots, P_N$$$ ($$$1 \le P_i \le 10^9$$$) — the prefix operation costs.

The fourth line contains $$$N$$$ integers $$$S_1, S_2, \dots, S_N$$$ ($$$1 \le S_i \le 10^9$$$) — the suffix operation costs.


Output Format

Print a single integer — the minimum total cost required to make all elements of $$$A$$$ non-negative.


Sample Cases

Sample 1

Input

3
-4 -6 -3
6 2 7
7 2 9

Output

14

Explanation

Initially $$$A = [-4, -6, -3]$$$. * Apply prefix operation at $$$i = 2$$$ with magnitude $$$4$$$ (cost: $$$4 \times P_2 = 4 \times 2 = 8$$$).
$$$A$$$ becomes $$$[-4 + 4, -6 + 4, -3] = [0, -2, -3]$$$. * Apply suffix operation at $$$i = 2$$$ with magnitude $$$3$$$ (cost: $$$3 \times S_2 = 3 \times 2 = 6$$$).
$$$A$$$ becomes $$$[0, -2 + 3, -3 + 3] = [0, 1, 0]$$$. All elements are now non-negative. Total cost: $$$8 + 6 = 14$$$.


Sample 2

Input

4
-5 -2 -6 -4
10 3 8 12
4 9 2 7

Output

22

Explanation

We perform: * $$$5$$$ suffix operations at index $$$1$$$ (cost $$$5 \times S_1 = 5 \times 4 = 20$$$). This adds $$$+5$$$ to all elements $$$A[1 \dots 4]$$$. * $$$1$$$ suffix operation at index $$$3$$$ (cost $$$1 \times S_3 = 1 \times 2 = 2$$$). This adds $$$+1$$$ to elements $$$A[3 \dots 4]$$$. The resulting array is:

$$$[-5 + 5, -2 + 5, -6 + 5 + 1, -4 + 5 + 1] = [0, 3, 0, 2]$$$

All elements are non-negative. Total cost: $$$20 + 2 = 22$$$.


Sample 3

Input

3
5 0 10
1 1 1
1 1 1

Output

0

Explanation

All elements are already non-negative, so no operations are required (cost $$$0$$$).


Editorial & Solution Architecture

Полный текст и комментарии »

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится