Submission #1122661

#TimeUsernameProblemLanguageResultExecution timeMemory
1122661imarnStove (JOI18_stove)C++20
100 / 100
22 ms2244 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);
    int n,k;cin>>n>>k;
    ll a[n];cin>>a[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-1]-rs-a[0]+1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...