贪心:Alice优先拿最大的,Bob也优先那最大的
Bob的策略,把每个回合的次大值增加到尽量和最大值相近
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include "bits/stdc++.h"
using namespace std;
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fios ofstream("test.txt");cout.rdbuf(out.rdbuf())
#define endl "\n"
#define INF 0x3f3f3f3f
#define MINF 2146473647
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) (x & (-x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 200010;
int n, k;
int a[N];
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int T;
cin >> T;
while(T--)
{
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n, cmp);
for(int i = 1; i < n; i += 2)
{
int d = a[i - 1] - a[i];
if(k >= d)
{
a[i] = a[i - 1];
k -= d;
}
else
{
a[i] += k;
k = 0;
}
}
int cntA = 0, cntB = 0;
for(int i = 0; i < n; i++)
if(i % 2) cntB += a[i];
else cntA += a[i];
cout << cntA - cntB << endl;
}
return 0;
}