You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
646 B
C++
31 lines
646 B
C++
#include <cstdio>
|
|
#include <cctype>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
void getint(int &x)
|
|
{
|
|
int ch = x = 0;
|
|
while (!isdigit(ch = getchar()))
|
|
;
|
|
for (; isdigit(ch); ch = getchar())
|
|
x = x * 10 + ch - '0';
|
|
}
|
|
const int N = 1e5 + 10;
|
|
int a[N];
|
|
int main()
|
|
{
|
|
int T, n, m;
|
|
getint(T);
|
|
while (T--)
|
|
{
|
|
getint(n), getint(m);
|
|
for (int i = 0; i < n; i++)
|
|
getint(a[i]);
|
|
sort(a, a + n);
|
|
long long ans = 0;
|
|
for (int i = 0; i < m; i++)
|
|
ans += a[i] * a[2 * m - i - 1];
|
|
printf("%lld\n", ans);
|
|
}
|
|
return 0;
|
|
} |