I found an interesting problem on https://www.codechef.com/problems/MTYFRI:
Motu and Tomu are very good friends who are always looking for new games to play against each other and ways to win these games. One day, they decided to play a new type of game with the following rules:
- The game is played on a sequence $A_0, A_1, \dots, A_{N-1}$.
- The players alternate turns; Motu plays first, since he's earlier in lexicographical order.
- Each player has a score. The initial scores of both players are $0$.
- On his turn, the current player has to pick the element of $A$ with the lowest index, add its value to his score and delete that element from the sequence $A$.
- At the end of the game (when $A$ is empty), Tomu wins if he has strictly greater score than Motu. Otherwise, Motu wins the game.
In other words, Motu starts by selecting $A_0$, adding it to his score and then deleting it; then, Tomu selects $A_1$, adds its value to his score and deletes it, and so on.
Motu and Tomu already chose a sequence $A$ for this game. However, since Tomu plays second, he is given a different advantage: before the game, he is allowed to perform at most $K$ swaps in $A$; afterwards, the two friends are going to play the game on this modified sequence.
Now, Tomu wants you to determine if it is possible to perform up to $K$ swaps in such a way that he can win this game.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains two space-separated integers $N$ and $K$ denoting the number of elements in the sequence and the maximum number of swaps Tomu can perform.
- The second line contains $N$ space-separated integers $A_0, A_1, \dots, A_{N-1}$.

-----Output-----
For each test case, print a single line containing the string "YES" if Tomu can win the game or "NO" otherwise (without quotes).

-----Constraints-----
- $1 \le T \le 100$
- $1 \le N \le 10,000$
- $0 \le K \le 10,000$
- $1 \le A_i \le 10,000$ for each valid $i$

-----Subtasks-----
Subtask #1 (20 points): $1...

I tried it in Python, but could not do it. Can you solve it?
for _ in range(int(input())):
 n,k = list(map(int,input().split()))
 a = list(map(int,input().split()))
 m = []
 t = []
 for i in range(n):
  if(i%2 == 0):
   m.append(a[i])
  else:
   t.append(a[i])
 m.sort(reverse=True)
 t.sort()
 mi=min(len(m),len(t))
 x1=0
 x2=0
 while(k!=0 and x1<len(m) and x2<len(m)):
  if(m[x1]>t[x2]):
   m[x1],t[x2] = t[x2],m[x1]
   x1+=1
   x2+=1
  else:
   break
  k-=1
 if(sum(t) > sum(m)):
  print("YES")
 else:
  print("NO")