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 ll long long int
#define ld long double
#define ii int
#define pb push_back
#define fi first
#define se second
#define Op operator
#define bp __builtin_popcount
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define TT ll tt;cin>>tt;while(tt--){Test_Case();}
#define T Test_Case() ;
using namespace std;
const ii N = 2e5 , M = 1e6 , mod = 1e9 + 7 , Ones = 1 , Zero = 0;
const ll oo = 1e18 ;
ii a[N + 5] ;
bool comp(ii aa , ii bb) {
return aa > bb ;
}
void Test_Case(){
ii n , k , ans = 0 ; cin >> n >> k ;
for(ii i = 1 ; i <= n ; i ++) {
cin >> a[i] ;
}
vector<ii> v ; ans = a[n] - a[1] + 1 ;
for(ii i = 2 ; i <= n ; i ++) v.pb(a[i] - a[i - 1] - 1) ;
sort(v.begin() , v.end() , comp) ;
for(ii i = 0 ; i < k - 1 ; i ++) ans -= v[i] ;
cout << ans << endl ;
}
int main(){
Faster
T ;
}
////// // // // // //////
// // // // // //
////// ////// //// //
// // // // //
////// // // // ////////
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |