제출 #1181136

#제출 시각아이디문제언어결과실행 시간메모리
1181136Born_To_LaughStove (JOI18_stove)C++17
100 / 100
13 ms1864 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(sth) sth.begin(), sth.end()
using namespace std;
typedef long long ll;
[[maybe_unused]] const ll MOD = 998244353, INF = 1e9 + 7;
#define int ll
void solve(){
    int n, k;cin >> n >> k;
    int ans = 0;
    vector<int> a(n);
    vector<int> b(n-1);
    for(int i=0; i<n; ++i){
        cin >> a[i];
        // ans += a[i];
    }
    ans += a[n-1] - a[0] + 1;
    if(k >= n){
        cout << n << '\n';
        return;
    }
    
    for(int i=0; i<n-1; ++i){
        b[i] = a[i+1] - a[i] - 1;
    }
    sort(alle(b), [](int a, int b){
        return a > b;
    });
    
    for(int i=0; i<k-1; ++i){
        ans -= b[i];
    }
    cout << ans << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...