이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(a, b) for(int a = 0; a < (b); a++)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vl;
const int N=1e6+10;
int t[N];
void solve(){
int n,k;
cin>>n>>k;
rep(i,n) cin>>t[i];
vi v;
sort(t,t+n);
ll curr=0;
curr=t[n-1]-t[0]+1;
for(int i=1;i<n;i++) v.push_back(t[i]-t[i-1]-1);
sort(v.begin(),v.end());
for(int i=v.size()-1;i>max(-1,(int)v.size()-k);i--) curr-=v[i];
cout<<curr<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |