Submission #1241917

#TimeUsernameProblemLanguageResultExecution timeMemory
1241917nguyendinhminhStove (JOI18_stove)C++20
100 / 100
12 ms2244 KiB
#include <bits/stdc++.h>
using namespace std;
#define minh main
#define endl "\n"
#define int long long
#define LIM 100000

int n , k , x[LIM+3] ;
vector <int> a ;

signed minh() {
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    cout.tie(0) ;
    cin >> n >> k ;
    for (int i=1 ; i<=n ; i++) {
        cin >> x[i] ;
    }

    for (int i=2 ; i<=n ; i++) {
        a.push_back(x[i] - x[i-1]) ;
    }
    sort(a.begin() , a.end() , greater<int>()) ;

    int c = n - k , ans = 0 ;
    while(c--) {
        ans += a.back() ;
        a.pop_back() ;
    }

    cout << ans + k ;
    return 0;
}






#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...