제출 #1342437

#제출 시각아이디문제언어결과실행 시간메모리
1342437inimadStove (JOI18_stove)C++20
100 / 100
14 ms1468 KiB
#include<bits/stdc++.h>
using namespace std;

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n, k;
    cin >> n >> k;    
    int a[n];
    vector<int> v;

    for(auto &i : a) cin >> i;

    LL ans = a[n-1] - a[0] + 1;

    for(int i = 1; i < n; i++){
        v.push_back(a[i] - a[i-1] - 1);
    }    

    sort(v.rbegin(), v.rend());

    for(int i = 0; i < k-1; i++) ans -= v[i];

    cout << ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…