# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
971848 | Sunbae | Stove (JOI18_stove) | C++17 | 18 ms | 3284 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>
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
ll a[N];
signed main(){
int n; ll k; scanf("%d %lld", &n, &k);
for(int i = 0; i<n; ++i) scanf("%lld", a+i);
sort(a, a+n);
vector<ll> v;
for(int i = 0; i<n-1; ++i) v.push_back(a[i] - a[i+1]);
sort(v.begin(), v.end());
ll ans = k + a[n-1] - a[0];
for(int i = 0; i<k-1; ++i) ans += v[i];
printf("%lld", ans);
}
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... |