#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define F first
#define S second
#define p_b push_back
#define ll long long
#define int long long
using namespace std ;
const int MOD = 1e9 + 7 ;
const int INF = 2e9 ;
int n , m , k ;
vector <int> a , b ;
set <int> s ;
void solve (){
cin >> n >> k ;
a.resize (n) ;
for (auto &i : a)
cin >> i ;
int ans = a.back () + 1 - a [0] ;
b.resize (n) ;
for (int i = 0 ; i < n - 1 ; i++){
b [i] = a [i + 1] - (a [i] + 1) ;
}
sort (b.rbegin () , b.rend ()) ;
for (int i = 1 ; i < k ; i++){
ans -= b [i - 1] ;
cerr << b [i - 1] << ' ' ;
}
cout << ans ;
}
int32_t main (){
ios_base::sync_with_stdio (0) ; cin.tie (0) ; cout.tie (0) ;
int t = 1 ;
//cin >> t ;
while (t--){
solve () ;
cout << '\n' ;
}
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... |