# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107429 | evpipis | Stove (JOI18_stove) | C++14 | 40 ms | 2420 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;
#define pb push_back
const int len = 1e5+5;
int arr[len];
vector<int> vec;
bool comp(int a, int b){
return (a > b);
}
int main(){
int n, k, ans;
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", &arr[i]);
k = min(k-1, n-1);
for (int i = 1; i < n; i++)
vec.pb(arr[i+1]-arr[i]-1);
sort(vec.begin(), vec.end(), comp);
ans = arr[n]-arr[1]+1;
for (int i = 0; i < k; i++)
ans -= vec[i];
printf("%d\n", ans);
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... |