#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
int main() {
int n,k; cin>>n>>k;
ll T[n];
vector<ll> inbet; //inbetween
/*
k matches, prioritize time
say k=1: optimal time is for L-F+1, as in s2
say k=2: optimal time depends, would pick the two consec numbers
w/ the biggest diff
so inbet are possible windows between each entry
when k=3
*/
for(int i=0; i<n; i++) cin>>T[i];
ll ans=T[n-1]-T[0]+1; // k=1
for(int i=1; i<n; i++) inbet.push_back(T[i]-T[i-1]-1); // each each
sort(all(inbet)); reverse(all(inbet)); // ordeno casitos para restarlos y los VOLTEO minpos
for(int i=0; i<k-1; i++) ans-=inbet[i];
cout<<ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |