No.2852 Yakitori Optimization Problem
タグ : / 解いたユーザー数 136
作問者 :
sepa38
Problem Statement
$N$ skewers of yakitori are lined up in a row.
The deliciousness of the $i$-th yakitori from the left is $A_i$.
Each of these yakitori will be given a topping of either salt or tare sauce. Of the $N$ yakitori, $K$ will be topped with salt and $N - K$ will be topped with tare sauce.
Topping the $i$-th yakitori from the left with salt increases its deliciousness by $B_i$, and topping it with tare sauce increases its deliciousness by $C_i$.
Since sepa-kun wants to eat yakitori that is as delicious as possible, he decided to apply the toppings so as to maximize the total deliciousness.
Find the maximum possible value of the total deliciousness of the $N$ yakitori.
Constraints
- $1 \leq N \leq 2 \times 10^{5}$
- $0 \leq K \leq N$
- $1 \leq A_i \leq 10^{9}$
- $1 \leq B_i, C_i \leq 10^{9}$
- All input values are integers.
Input
The input is given from standard input in the following format.
$N$ $K$ $A_1$ $A_2$ ... $A_N$ $B_1$ $B_2$ ... $B_N$ $C_1$ $C_2$ ... $C_N$
Output
Output the answer to the problem on one line.
Sample
Sample 1
Input
3 2 2 3 5 5 7 6 4 9 2
Output
30
If the $1$-st and $3$-rd yakitori from the left are topped with salt and the $2$-nd yakitori is topped with tare sauce, the total deliciousness is $(2 + 5) + (3 + 9) + (5 + 6) = 30$, which is the maximum.
Sample 2
Input
10 4 6 35 90 38 69 51 66 40 92 74 53 83 46 26 3 48 50 38 67 66 32 52 20 47 51 77 24 77 26 6
Output
1131
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。