Submission #1311988

#TimeUsernameProblemLanguageResultExecution timeMemory
1311988ozxpnguinStove (JOI18_stove)C++20
100 / 100
15 ms2384 KiB
// Source : https://usxco.guide/generarl/io
 
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second 
#define PII pair<int,int>
#define pb push_back
#define sz(x) (int)(x).size()
#define tso(x) to_string(x)
#define all(x) (x).begin(), (x).end()   
 
const int MOD = 1e9+7;
const int INF = 1e18 + 18;
const int mxN = 2e5+5;

void solve() {
    int n,k; cin >> n >> k;
    vector<int>ar(n);
    for ( int i = 0; i<n; i++ ) cin >> ar[i];
    vector<int>gap;
    for (int i = 0; i<n-1; i++) gap.pb(ar[i+1]-ar[i]-1);
    sort(all(gap),greater<int>());
    int vl = (ar[n-1] + 1) - ar[0] , emyu = k - 1;
    for ( int i = 0; i<sz(gap) && i < emyu; i++ ) vl -= gap[i];
    cout << vl << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
    return 0;
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...