(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #1123898

#TimeUsernameProblemLanguageResultExecution timeMemory
1123898vjudge1Robots (APIO13_robots)C++17
In queue
0 ms320 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; }