제출 #1229037

#제출 시각아이디문제언어결과실행 시간메모리
1229037nguyentuankhangtpStove (JOI18_stove)C++20
100 / 100
13 ms1616 KiB
#include<bits/stdc++.h>
using namespace std;
const long long N=1e5+5;
bool ok[N];
vector<int>a(N),tim(N);
int ans=0;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 1;i <= n ; i++) cin >> a[i];
    ans=a[n]-a[1]+1;
    for(int i = 2;i<=n;i++){
        tim.push_back(a[i]-a[i-1]-1);
    }
    sort(tim.rbegin(),tim.rend());
    for(int i=0; i< k-1 and i < tim.size();i++){
        ans-=tim[i];
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...