# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208736 | tushar_2658 | Stove (JOI18_stove) | C++14 | 34 ms | 3312 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"
using namespace std;
const int maxn = 100005;
using ll = long long;
ll a[maxn];
int main(int argc, char const *argv[])
{
// freopen("in.txt", "r", stdin);
int n, k;
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; i++){
scanf("%lld", &a[i]);
}
sort(a + 1, a + n + 1);
vector<ll> v;
for(int i = 2; i <= n; i++){
v.push_back(a[i] - a[i - 1]);
}
sort(v.begin(), v.end(), greater<ll>());
ll ans = 0;
int cnt = 0;
for(int i = 0; i < (int)v.size(); i++){
if(i < k - 1){
ans++;
}else {
ans += v[i];
}
}
cout << ans + 1 << endl;
return 0;
}
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... |