Submission #768495

#TimeUsernameProblemLanguageResultExecution timeMemory
768495LinkedArrayStove (JOI18_stove)C++17
100 / 100
16 ms2148 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 10;

int t[MAXN], timeDif[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, k, i;

    cin >> n >> k;
    cin >> t[0];

    for(i = 1; i < n; i++){
        cin >> t[i];
        timeDif[i] = t[i] - t[i - 1]; // How much time the stove runs
    }
    sort(timeDif + 1, timeDif + n); // Sort to get the minimum time
    int ans = n;
    for(i = 1; i <= n - k; ++i){ // He can turn it on at most K times, so we go until N - K
        ans += --timeDif[i];
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...