Submission #160649

#TimeUsernameProblemLanguageResultExecution timeMemory
160649XCoderStove (JOI18_stove)C++14
100 / 100
47 ms1916 KiB
#include <bits/stdc++.h>

#define FOR(i,s,e) for(int i=(s);i<(int)(e);i++)
#define FOE(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define REP(i,n)   FOR(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define CLR(s) memset(s,0,sizeof(s))
#define PB push_back

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pll;
typedef map<int,int> mii;
typedef vector<int> vi;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K; cin >> N >> K;
    int X, Y; cin >> X;

    vi A;
    REP(_, N - 1) {
        cin >> Y;
        if (Y - X - 1 != 0) {
            A.PB(Y - X - 1);
        }
        X = Y;
    }
    sort(ALL(A));

    LL Ans = N;
    REP(i, max(0, int(A.size()) - K + 1)) Ans += A[i];

    cout << Ans << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...