Submission #962953

#TimeUsernameProblemLanguageResultExecution timeMemory
962953marinalucaStove (JOI18_stove)C++14
100 / 100
20 ms2284 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimize ("O4")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")

using namespace std;
#define int long long
#define ll long long
#define XX first
#define YY second
#define pb push_back
#define sz (x) int(x.size())
#define pf pop_front
#define pob pop_back
#define pff push_front

signed main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    if (k >= n){
        cout << n;
        return 0;
    }
    else{
        vector <int> v;
        int x, cp;
        cin >> x;
        cp = x;
        int sum = n;
        for (int i = 0; i < n - 1; ++ i){
            cin >> x;
            v.push_back(x - cp - 1);
            cp = x;
        }
        sort (v.begin(), v.end());
        for (int i = 0; i < n - k; ++ i){
            sum += v[i];
        }
        cout << sum;
    }
    return 0 ^ 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...