PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000034. Trò chơi của các vận động viên toán (Game of Mathletes)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn integers on a blackboard, where nn is even. An integer kk is fixed and the initial score is 00. Exactly n/2n/2 turns are played. On each turn, Alice erases one remaining integer, then Bob erases another remaining integer. If the two removed numbers sum to kk, the score increases by 11.

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 nn and kk: the number of integers on the blackboard and the target sum.
  • The second line contains exactly nn integers x1,x2,…,xnx_1,x_2,\ldots,x_n.

Output

Print one integer: the final score if both Alice and Bob play optimally.

Subtasks

  • Subtask 1 (20 points): 2≤n≤82\le n\le 8; nn is even; 1≤k≤2n1\le k\le2n; 1≤xi≤n1\le x_i\le n for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le 2000; nn is even; 1≤k≤2n1\le k\le2n; 1≤xi≤n1\le x_i\le n for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 2≤n≤2000002\le n\le 200000; nn is even; 1≤k≤2n1\le k\le2n; 1≤xi≤n1\le x_i\le n for all 1≤i≤n1\le i\le n.

Examples

Input

4 4
1 2 3 2

Output

2

Explanation

The numbers are 1,2,3,21,2,3,2 and k=4k=4. They can be partitioned into two disjoint pairs that sum to 44: (1,3)(1,3) and (2,2)(2,2). Whatever number Alice removes from either pair, Bob can remove its complement and score 11. The remaining pair gives another point. There are only two turns, so the answer is 22.