#P13507. [OOI 2024] Three Arrays

[OOI 2024] Three Arrays

题目描述

You are given three arrays DD, LL, and RR of length nn, with elements indexed from 11, as well as the integers a0a_{0} and b0b_{0}. You construct two arrays AA and BB of length n+1n+1 according to the following rules:

  • A0=a0A_{0} = a_{0}, B0=b0B_{0} = b_{0}
  • For all ii from 11 to nn, perform the following actions:
    • Set the elements as Ai=Ai1+DiA_{i} = A_{i - 1} + D_{i} and Bi=Bi1+DiB_{i} = B_{i - 1} + D_{i}.
    • Choose exactly one\textbf{one} of the following operations and apply it:
      • Ai=min(Ai,Li)A_{i} = \min(A_{i}, L_{i})
      • Bi=min(Bi,Ri)B_{i} = \min(B_{i}, R_{i})

You want to construct arrays AA and BB to maximize the value of An+BnA_{n} + B_{n}. Find the maximum value of An+BnA_{n} + B_{n} that can be obtained by performing the described actions.

输入格式

The first line contains a single integer nn (1n1000001 \le n \le 100\,000) --- the length of arrays DD, LL, and RR.

The second line contains nn integers D1, D2, , DnD_{1},\ D_{2},\ \ldots,\ D_{n} (0Di1090 \le D_{i} \le 10^{9}) --- the array DD.

The third line contains nn integers L1, L2, , LnL_{1},\ L_{2},\ \ldots,\ L_{n} (0Li1090 \le L_{i} \le 10^{9}) --- the array LL.

The fourth line contains nn integers R1, R2, , RnR_{1},\ R_{2},\ \ldots,\ R_{n} (0Ri1090 \le R_{i} \le 10^{9}) --- the array RR.

The fifth line contains two integers a0a_{0} and b0b_{0} (0a0,b01090 \le a_{0}, b_{0} \le 10^{9}).

输出格式

Output a single integer --- the maximum possible value of An+BnA_{n} + B_{n} among all possible ways to construct arrays AA and BB.

5
4 0 7 0 8
10 5 3 7 7
8 5 9 2 23
4 8
34

提示

Note

In the first set of input data, the following sequence of actions leads to the maximum answer:

  • A0=4A_{0} = 4, B0=8B_{0} = 8.
  • A1=A0+D1=4+4=8A_{1} = A_{0} + D_{1} = 4 + 4 = 8, B1=B0+D1=8+4=12B_{1} = B_{0} + D_{1} = 8 + 4 = 12.
  • The minimum is applied to A1=min(A1,L1)=min(10,8)=8A_{1} = \min(A_{1}, L_{1}) = \min(10, 8) = 8, the value of B1=12B_{1} = 12 remains the same.
  • A2=A1+D2=8+0=8A_{2} = A_{1} + D_{2} = 8 + 0 = 8, B2=B1+D2=12+0=12B_{2} = B_{1} + D_{2} = 12 + 0 = 12.
  • The minimum is applied to A2=min(A2,L2)=min(5,8)=5A_{2} = \min(A_{2}, L_{2}) = \min(5, 8) = 5, the value of B2=12B_{2} = 12 remains the same.
  • A3=A2+D3=12A_{3} = A_{2} + D_{3} = 12, B3=B2+D3=19B_{3} = B_{2} + D_{3} = 19.
  • The minimum is applied to A3=min(A3,L3)=3A_{3} = \min(A_{3}, L_{3}) = 3, the value of B3=19B_{3} = 19 remains the same.
  • A4=A4+D3=3A_{4} = A_{4} + D_{3} = 3, B4=B3+D4=19B_{4} = B_{3} + D_{4} = 19.
  • The minimum is applied to A4=min(A4,L4)=3A_{4} = \min(A_{4}, L_{4}) = 3, the value of B4=19B_{4} = 19 remains the same.
  • A5=A5+D4=11A_{5} = A_{5} + D_{4} = 11, B5=B4+D5=27B_{5} = B_{4} + D_{5} = 27.
  • The value of A5=11A_{5} = 11 remains the same, B5=min(B5,R5)=min(27,23)=23B_{5} = \min(B_{5}, R_{5}) = \min(27, 23) = 23.
  • A5+B5=11+23=34A_{5} + B_{5} = 11 + 23 = 34.

It can be shown that this is the maximum value.

Scoring

The tests for this problem consist of six groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. Offline-evaluation\textbf{Offline-evaluation} means that the results of testing your solution on this group will only be available after the end of the competition.

Group Points Additional constraints < Required groups Comment
nn DiD_i
0 -- -- -- Examples.
1 13 n15n \le 15 0
2 18 n300n \le 300 0, 1
3 14 n5000n \le 5000 Di=0D_{i} = 0 --
4 16 -- 0--3
5 19 -- Di=0D_{i} = 0 3
6 20 -- 0--5 Offline-evaluation.