# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548872 | DemonLord154 | Stove (JOI18_stove) | C++14 | 0 ms | 0 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<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int solve(int n, vector<int> & times, int k){
vector<int> gaps(n-1);
for (int i=0;i<n-1;i++){
gaps[i]=times[i+1]-times[i]-1;
}
sort(gaps.begin(),gaps.end(),greater<int>());
int answer= times[n-1]-times[0]+1
for (int i=0;i<k-1;i++){
answer-=gaps[i];
}
return answer;
}
int main(){
int n,k;
cin>>n>>k;
vector <int> times(n);
for (int i=0;i<n;i++){
cin>>times[i];
}
cout<<solve(n,times,k)<<"\n";
return 0;
}