Submission #395120

#TimeUsernameProblemLanguageResultExecution timeMemory
395120jeroenodbStove (JOI18_stove)C++14
100 / 100
56 ms1612 KiB
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
int main() {
    int n,k; cin >> n >> k;
    vi t(n); for(int& i : t) cin >> i;
    int ans = n;
    for(int i=1;i<n;++i) {
        t[i-1] = t[i]-t[i-1]-1;
    }
    t.pop_back();
    sort(all(t));
    for(int i=0;i<n-k;++i) {
        ans+=t[i];
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...