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 pb push_back
#define pf push_front
#define f1 first
#define f2 second
#define ll long long
#define pii pair<int,int>
#define fastio() cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false) //no scanf
#define fileio(code) freopen("code.in","r",stdin);freopen("code.out","w",stdout) //file name
using namespace std;
//https://oj.uz/problem/JOI18_stove
int n,k,x,y,ans,mn=INT_MAX,mx=INT_MIN;
vector<int> v;
int main(){
fastio();
cin>>n>>k;
cin>>x;
mn=min(mn,x);
mx=max(mx,x);
for(int i=1;i<n;i++){
cin>>y;
mn=min(mn,y);
mx=max(mx,y);
v.pb(y-x-1);
x=y;
}
sort(v.rbegin(),v.rend());
for(int i=0;i<k-1;i++) ans+=v[i];
cout<<mx-mn+1-ans;
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... |