?
?思路:
1、将数据从大到小排序
2、用前缀和
3、每次用总和减去2倍的乘-1的数,求最大值
代码:
#include <iostream>
#include<algorithm>
using namespace std;
void solve() {
int n, k, x;
cin >> n >> k >> x;
int A[200020] = {};
for (int i = 1; i <= n; i++)
cin >> A[i];
sort(A + 1, A + n + 1, greater<int>());//降序排列
for (int i = 1; i <= n; i++)
A[i] += A[i - 1];
int ans = -1e9;
for (int i = 0; i <= k; i++)
ans = max(ans, (A[n] - 2 * A[min(i + x, n)] + A[i]));
cout << ans << "\n";
}
int main()
{
int tc;
cin >> tc;
while (tc--)
solve();
}