제출 #1150897

#제출 시각아이디문제언어결과실행 시간메모리
1150897danglayloi1Stove (JOI18_stove)C++20
100 / 100
21 ms1480 KiB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
using ll = long long;
const ll mod=1e9+7;
const int nx=1e5+5;
int n, k, a[nx];
vector<int> len;
ll ans;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    for(int i = 1; i <= n; i++)
        cin>>a[i];
    if(n==1) return cout<<k, 0;
    sort(a+1, a+n+1);
    ans=a[n]-a[1]+1;
    for(int i = 1; i < n; i++)
        len.emplace_back(a[i+1]-a[i]-1);
    sort(len.begin(), len.end(), greater<int>());
    for(int i = 0; i < k-1; i++)
        ans-=len[i];
    cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...