https://codeforces.com/contest/1506/problem/D
题意:给你包含若干个数的集合,每次操作可以选择两个互不相同的数从该集合中移除,怎样操作能使集合所剩的数最小?
先用map来记录每个数字出现的次数,生成一个新数组,然后将其从小到大排序。因为我们是想让最后剩下的数尽可能少,所以我们每次贪心地让最大和第二大的元素-1,直到无法操作为止。这个操作使用优先队列就可以实现。
还有种做法是如果最大的元素比剩下的元素和要大,那么答案就是他们的差。反之就去判断所有元素和的奇偶性,偶数就能消为0,奇数就能消到1.
//使用优先队列模拟操作
#include <bits/stdc++.h>
using namespace std;
#define qc ios::sync_with_stdio(0)
#define ll long long
#define pb push_back
ll a[200001];
map<ll, ll>b;
vector<ll>uni;
int main() {
// qc, cin.tie(0);
int t;
cin >> t;
while (t--) {
uni.clear(), b.clear();
priority_queue<int> q;
int n;
cin >> n;
for (int i = 0; i < n; i