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.
24 lines
585 B
C++
24 lines
585 B
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 505, M = N * N;
|
|
int a[N], b[M];
|
|
int main()
|
|
{
|
|
int n, k;
|
|
scanf("%d%d", &n, &k);
|
|
for (int i = 0; i < n; i++)
|
|
scanf("%d", a + i);
|
|
int cnt = 0;
|
|
for (int i = 0; i < n; i++)
|
|
for (int j = i + 1; j < n; j++)
|
|
b[cnt++] = a[i] + a[j];
|
|
sort(b, b + cnt);
|
|
long long ans = 0;
|
|
for (int i = cnt - k; i < cnt; i++)
|
|
ans += b[i];
|
|
printf("%lld", ans);
|
|
return 0;
|
|
}
|