D. Array and Operations:题目
之前写的了,直接上答案!
#include <bits/stdc++.h>
#define int long long
#define pII pair<int, int>
#define endl "\n"
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fer(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
using namespace std;
const int N = 3e5 + 11;
int a[N], b[N];
void solve()
{int n, k, res = 0;cin >> n >> k;for (int i = 1; i <= n; i++)cin >> a[i];sort(a+1, a + n+1);for (int i = 1; i <= n - 2 * k; i++)res += a[i];for (int i = n - 2 * k + 1; i <= n - k; i ++)if (a[i] == a[i + k])res++;cout << res << endl;
}
signed main()
{fast;int t;cin >> t;while (t--)solve();return 0;
}
为什么一天只能上传10篇!!!可恶!!