Submission #1147622

#TimeUsernameProblemLanguageResultExecution timeMemory
1147622gulmixStove (JOI18_stove)C++20
100 / 100
13 ms1864 KiB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define oset tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //ifstream cin("cycle2.in");
    //ofstream cout("cycle2.out");
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    vector<ll> b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = n-1; i >= 1; i--){
        b[i] = a[i] - a[i-1] - 1;
    }
    sort(b.rbegin(), b.rend());
    ll ans = a[n-1] - a[0] + 1; 
    for(int i = 0; i < k-1; i++){
        ans -= b[i];
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...