제출 #160651

#제출 시각아이디문제언어결과실행 시간메모리
160651XCoderStove (JOI18_stove)C++14
100 / 100
27 ms1184 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;
    vi A(N); REP(i, N) cin >> A[i];
    vi D(N - 1); REP(i, N - 1) D[i] = A[i + 1] - A[i];
    
    sort(ALL(D));
    LL Ans = accumulate(begin(D), next(begin(D), N - K), K);
    cout << Ans << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...