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;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 100100;
const ll INF = 1e18;
const ll MOD = 1e9+7;
ll A[MAXN];
ll ans;
vi V;
ll N,K,a,b;
int main(){
cin>>N>>K;
ans=N;
for (int i=1;i<=N;++i)cin>>A[i];
// for (int i=1;i<=N;++i)cout<<A[i]<<' ';cout<<'\n';
for (int i=1;i<N;++i)V.pb(A[i+1]-A[i]-1);
sort(ALL(V));reverse(ALL(V));
// for (auto i:V)cout<<i<<'\n';
--K;
while (SZ(V)>K){ans+=V.back();V.pop_back();}
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... |