//I love ManchesterUnited
#include<bits/stdc++.h>
using namespace std;
#define love ManchesterUnited
#define int long long
#define pb push_back
#define FOR(i,a,b) for (int i=(a); i<=(b); i++)
#define FORD(i,b,a) for (int i=(b); i>=(a); i--)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
#define ALL(a) (a).begin(),(a).end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define fi first
#define se second
#define endl '\n'
#define MASK(x) (1 << (x))
#define BIT(mask,i) ((mask >> i) & 1)
typedef long long ll;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e18;
int n,k;
int a[N];
int32_t main(){
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> k;
FOR(i,1,n) cin >> a[i];
vector <int> vec;
FOR(i,2,n) vec.pb(a[i] - (a[i - 1] + 1));
sort(ALL(vec),greater <int> ());
int ans = a[n] - a[1] + 1;
FOR(i,1,min(k - 1,(int)vec.size())){
ans -= vec[i - 1];
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |