이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bip(i) __builtin_popcount(i)
#define gb(i,j) ((i>>j)&1)
#define fi first
#define se second
using namespace std;
const int N=1e5+5;
int k , n , a[N];
ll res;
int gap[N];
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> k;
for( int i=1 ; i<=n ; i++ ){
cin >> a[i];
if(i>1)
gap[i] = a[i]-a[i-1]-1; // gap cua i va cai trc
// gap[i].se.fi = a[i-1]+1;
// gap[i].se.se = a[i];
res+=1;
}
sort(gap+2 , gap+1+n);
// for( int i=1 ; i<=n ; i++ )cout << i << " " << gap[i].fi << endl;
if(k<n){
k=n-k;
for( int i=1 ; i<=k ; i++ ){
res+=gap[i+1];
}
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |