Submission #1187848

#TimeUsernameProblemLanguageResultExecution timeMemory
1187848jerzykStove (JOI18_stove)C++20
100 / 100
11 ms840 KiB
#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1'000'000'000'000'000'000LL;
const int II = 2'000'000'000;
const ll M = 1'000'000'007LL;
const int N = 1'000'007;
int tab[N];

void Solve()
{
    int n, k, ans, x, p;
    cin >> n >> k;
    ans = n;
    cin >> p;
    for(int i = 1; i < n; ++i)
    {
        cin >> x;
        tab[i] = x - (p + 1);
        p = x;
    }
    sort(tab + 1, tab + n);
    for(int i = 1; i <= (n - 1) - (k - 1); ++i)
        ans += tab[i];
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t; cin >> t;
    //while(t--)
        Solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...