Submission #1255957

#TimeUsernameProblemLanguageResultExecution timeMemory
1255957maxbrucelenStove (JOI18_stove)C++17
100 / 100
12 ms1480 KiB
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
#define inf 1e18
#define maxn 200005
#define endl '\n'

int n,K,p[maxn];


main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>K;
    for(int i=1;i<=n;++i){
        cin>>p[i];
    }
    int as = p[n]-p[1]+1;
    K--;

    vector<int> tmp;
    for(int i=2;i<=n;++i){
        tmp.push_back(p[i]-p[i-1]-1);
    }
    sort(tmp.begin(),tmp.end(),greater<int>());

    for(int i:tmp){
        if(K==0) break;
        K--;
        as -= i;
    }
    cout<<as<<endl;
}

Compilation message (stderr)

stove.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...