#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <unordered_map>
#include <list>
#include <unordered_set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define INFI 987654321
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
int N, K;
vector<ll> data;
int main() {
ios_base::sync_with_stdio(false);
cin >> N >> K;
for(int i = 0; i < N; ++i) {
ll here;
cin >> here;
data.push_back(here);
}
sort(data.begin(), data.end());
ll ans = 0;
int cur = 0;
while(K > 1) {
K -= 2;
ans += data.back() - data[cur++];
data.pop_back();
}
if(K) {
ans += data.back();
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2180 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |