Submission #248832

#TimeUsernameProblemLanguageResultExecution timeMemory
248832rocks03Stove (JOI18_stove)C++14
100 / 100
25 ms2932 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define ff first
#define ss second
#define pb push_back

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K; cin >> N >> K;
    int a[N];
    for(int i = 0; i < N; i++) cin >> a[i];
    vector<ll> v;
    for(int i = 1; i < N; i++) v.pb(a[i] - a[i-1] - 1);
    sort(v.begin(), v.end(), greater<ll>());
    ll ans = N;
    for(int i = K-1; i < N-1; i++) ans += v[i];
    cout << ans;
}

Compilation message (stderr)

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