이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// author: Movlan
#define ll long long
//#define int long long
#define br "\n"
#define sp " "
#define pb push_back
#define pf push_front
typedef pair<ll,int> pii;
#define vi vector<int>;
#define vpii vector<pair<int,int>>
#define all(x) x.begin(),x.end()
#define sync ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
struct edge{
//int u;
int v;
ll w;bool operator<(edge const& other){return w<other.w;}
};
void solve(){
int n,k;
cin>>n>>k;
int arr[n];
ll res=n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
ll sum=0;
vector<int>diff;
for(int i=1;i<=n-1;i++){
diff.pb(arr[i]-arr[i-1]-1);
sum+=(arr[i]-arr[i-1]-1);
}
sort(all(diff));
k--;
for(int i=n-2;i>=0 && k!=0;i--) {
k--;
sum-=diff[i];
}
cout<<sum+res;
}
signed main() {
sync;
int t=1;
//cin >> t;
while(t--){
solve();
//cout<<br;
}
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... |