#TP0000034. Trò chơi của các vận động viên toán (Game of Mathletes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trò chơi của các vận động viên toán (Game of Mathletes)
Game of Mathletes
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Alice and Bob play a game with integers on a blackboard, where is even. An integer is fixed and the initial score is . Exactly turns are played. On each turn, Alice erases one remaining integer, then Bob erases another remaining integer. If the two removed numbers sum to , the score increases by .
Alice plays to minimize the final score, while Bob plays to maximize it. Both players make optimal decisions and know all remaining numbers. Determine the final score.
Input
- The first line contains and : the number of integers on the blackboard and the target sum.
- The second line contains exactly integers .
Output
Print one integer: the final score if both Alice and Bob play optimally.
Subtasks
- Subtask 1 (20 points): ; is even; ; for all .
- Subtask 2 (30 points): ; is even; ; for all .
- Subtask 3 (50 points): ; is even; ; for all .
Examples
Input
4 4
1 2 3 2
Output
2
Explanation
The numbers are and . They can be partitioned into two disjoint pairs that sum to : and . Whatever number Alice removes from either pair, Bob can remove its complement and score . The remaining pair gives another point. There are only two turns, so the answer is .