luogu#P8002. Alice and Bob are playing a Normal Game

Alice and Bob are playing a Normal Game

Problem Description

Given a sequence of length nn, Alice and Bob take turns performing a total of kk operations. In the ii-th operation, the current player must choose an integer in xixi-x_i \sim x_i and insert it at the beginning or the end of the sequence. Alice moves first (that is, when ii is odd, Alice inserts an integer in xixi-x_i \sim x_i; when ii is even, Bob inserts an integer in xixi-x_i \sim x_i).

Let the final sequence be a1,a2,,an+ka_1,a_2,\dots,a_{n+k}. The score is i=1n+k(1)i1ai\sum_{i=1}^{n+k} (-1)^{i-1}a_i. Alice wants to maximize the score, and Bob wants to minimize it. When both players use optimal strategies, find the final score.

Input Format

The first line contains two positive integers n,kn,k, representing the initial sequence length and the number of operations.

The next line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n, representing the initial sequence.

The next line contains kk non-negative integers, where the ii-th number is xix_i.

Output Format

Output one integer in one line, representing the answer.

2 2
1 3
2 2
-2

Hint

This problem uses bundled testdata.

Subtask ID Score Special Constraints
00 2525 n,k,xi5n,k,x_i\le 5
11 n,k10n,k\le 10
22 n,k100n,k\le 100
33 No special constraints

For all testdata, it is guaranteed that 1n,k2×1051\le n,k\le 2\times 10^5 and 0ai,xi1090\le |a_i|,x_i\le 10^9.

This problem has many test points. To ensure judging speed, the time limit is 500 ms, and it is guaranteed to be more than 5 times the maximum time used by the standard solution.

Translated by ChatGPT 5