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>
using namespace std;
#pragma GCC optimize("O3")
bool pc(pair<int,int> a,pair<int,int> b){
return a.second-a.first<b.second-b.first;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,k;cin>>n>>k;vector<pair<int,int>> v;
int pv;cin>>pv;
for(int i=1;i<n;i++){int k;cin>>k;v.push_back({pv,k});pv=k;}
sort(v.rbegin(),v.rend(),pc);
//for(auto i:v){cerr<<i.first<<' '<<i.second<<endl;}
long long s=n,r=n;
while(r>k){
int a,b;tie(a,b)=v.back();v.pop_back();r--;
s+=(long long)b-(a+1);
}
cout<<s<<endl;
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... |