이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |