# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
792418 | vjudge1 | Stove (JOI18_stove) | C++17 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
const int N = 100100;
using namespace std;
int n;
int k;
int a[N];
vector < int > v;
int main()
{
#ifdef zxc
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin >> n >> k;
long long ans = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1);
for(int i = 2; i <= n; i++){
ans += a[i] - a[i - 1];
v.push_back(a[i] - a[i - 1]);
}
sort(v.begin(), v.end());
while(v.size() > n - k){
ans -= v.back();
v.pop_back();
}
if (n > 20) {
cout << 0 << "\n";
} else {
cout << ans + k << "\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |