Tên đăng nhập Điểm ▾ Bài tập Giới thiệu
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0

[user:enter username here]

36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0

include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 5;
long long k, n, ans = 0, a[maxn];

void nhap()
{
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
sort(a+1,a+n+1,greater<int>());
}

int main()
{
nhap();

for(int i = 1; i <= k+1; i++)
    ans+=a[i]+a[i+1];
for(int i = k + 2; i <= n; i++)
    ans-=a[i];

cout << ans;

return 0;
}

36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901
phkhanhs410
Phạm Nam Khánh
0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901
noel 1203
0 0
36901 0 0
36901
Nahhh 1203
0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901 0 0
36901
huylabibeo
Huy la bí beo
0 0

36901 0 0
36901 0 0

:v

36901
hoangnguyen27
Hoàng Nguyên
0 0

Hello!
:V

36901 0 0
36901 0 0
36901 0 0