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;
typedef long long ll;
#define pb push_back
#define pii pair<int,int>
#define FOR(i, a, b) for(int i=(signed)(a); i<=(signed)(b); i++)
#define F0R(i, a) for(int i=(0); i<(signed)(a); i++)
const int MXN = 1e5 + 10;
ll T[MXN] = {0};
int main(){
//faster io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, K;
cin>>N>>K;
FOR(i, 1, N) cin>>T[i];
K--;
ll ans = T[N] + 1 - T[1];
multiset<ll> st;
FOR(i, 2, N){
st.insert(-(T[i]-T[i-1]-1));
}
for(ll i: st){
if(K==0) break;
ans+=i;
K--;
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |