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>
#define f first
#define s second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
ll diff[100001];
ll v[100001];
int N,K;
ll s=0;
int main(){
cin>>N>>K;
for(int i=0;i<N;i++)cin>>v[i];
for(int i=0;i<N-1;i++){
diff[i]=v[i+1]-v[i];
s+=diff[i];
}
sort(diff,diff+(N-1),greater<ll>());
for(int i=0;i<K-1;i++)s-=diff[i]-1;
cout<<s+1;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |