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 , Alice and Bob take turns performing a total of operations. In the -th operation, the current player must choose an integer in and insert it at the beginning or the end of the sequence. Alice moves first (that is, when is odd, Alice inserts an integer in ; when is even, Bob inserts an integer in ).
Let the final sequence be . The score is . 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 , representing the initial sequence length and the number of operations.
The next line contains integers , representing the initial sequence.
The next line contains non-negative integers, where the -th number is .
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 |
|---|---|---|
| No special constraints |
For all testdata, it is guaranteed that and .
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