제출 #1245431

#제출 시각아이디문제언어결과실행 시간메모리
1245431AMel0nStove (JOI18_stove)C++20
100 / 100
12 ms1864 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
ll N, K, v[100001], gap[100001], res = 0;
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K; 
    K--;
    FOR(i,N) {cin >> v[i]; if (i) gap[i] = v[i] - v[i-1] - 1;}
    nth_element(gap, gap + K, gap + N, greater<>());
    FOR(i,K) res -= gap[i];
    cout << res + v[N-1] + 1 - v[0];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...