#P9228. 原神

原神

Problem Description

In Genshin Impact, there is a mage who can cast nn Pyro attacks and mm Cryo attacks. The damage of each attack is a1,a2,,ana_1,a_2,\cdots, a_n and b1,b2,,bmb_1,b_2,\cdots, b_m, respectively.

The following reaction rules exist between elemental attacks:

  • Each elemental attack can apply the corresponding element to a monster with no elemental aura. Initially, the monster has no elemental aura.

  • If a Pyro attack hits a monster with a Cryo aura, then the damage of this attack will be ×2\times 2, and the elemental aura is cleared.

  • If a Cryo attack hits a monster with a Pyro aura, then the damage of this attack will be +k+k, and the elemental aura is cleared.

Now the mage may arrange the attack order arbitrarily. That is, after each attack, the mage can choose any unused spell to cast next. She wants to maximize the total damage. Find the maximum total damage.

Input Format

The first line contains three integers n,m,kn,m,k.

The second line contains nn integers a1,a2,,ana_1,a_2,\cdots, a_n.

The third line contains mm integers b1,b2,,bmb_1,b_2,\cdots, b_m.

Output Format

Output one integer in one line, representing the answer.

6 7 3
1 1 4 5 1 4
1 9 1 9 8 1 0

67

5 3 5
1 4 2 8 5
7 1 4

50
1 1 0
2
3

7

见附件中的 samples/genshin4.in
见附件中的 samples/genshin4.ans
见附件中的 samples/genshin5.in
见附件中的 samples/genshin5.ans

Hint

Explanation for Sample 1

Use the order $a_1\rightarrow b_4\rightarrow a_2\rightarrow b_3\rightarrow a_5\rightarrow b_5\rightarrow b_7 \rightarrow b_1\rightarrow a_3 \rightarrow b_2\rightarrow a_4\rightarrow b_6 \rightarrow a_6$. The actual damage each time is 1,12,1,4,1,11,0,1,8,9,10,1,81,12,1,4,1,11,0,1,8,9,10,1,8, and the total damage is 6767.

Explanation for Sample 2

Use the order $a_5\rightarrow b_1\rightarrow b_2\rightarrow a_4\rightarrow a_3\rightarrow b_3\rightarrow a_2\rightarrow a_1$. The actual damage each time is 5,12,1,16,2,9,4,15,12,1,16,2,9,4,1, and the total damage is 5050.

Constraints

For 100%100\% of the testdata, 1n,m1061 \leq n,m \leq 10^6, 0ai,bi,k1090 \leq a_i,b_i,k \leq 10^9.

Test Point ID n,mn,m \leq Special Property
151 \sim 5 1010
6106 \sim 10 10001000
111211 \sim 12 10610^6 k=0k=0
131413 \sim 14 k>max(maxi=1n{ai},maxi=1m{bi})k>\max(\max_{i=1}^n\{a_i\},\max_{i=1}^m\{b_i\})
151615 \sim 16 n=mn=m
172517 \sim 25

Translated by ChatGPT 5