# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1123898 | vjudge1 | Robots (APIO13_robots) | C++17 | 0 ms | 320 KiB |
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define szz(r) (ll)r.size()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=1e5+5;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
ll n,k;cin>>n>>k;
ll a[n+1];a[0]=0;
priority_queue<ll>pq;
for(int i=1;i<=n;i++)cin>>a[i],pq.push(a[i]-a[i-1]-1);
k--;ll rs=0;
while(!pq.empty()&&k>0){
rs+=pq.top();pq.pop();k--;
}cout<<a[n]-rs;
}