제출 #1277870

#제출 시각아이디문제언어결과실행 시간메모리
1277870hoangtien69Stove (JOI18_stove)C++20
100 / 100
15 ms2252 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 5;

int t[MAXN];
int n;
int k;
vector<int> peal;
int res = 0;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> t[i];
    }
    res = t[n] - t[1] + 1;
    if (k >= n)
    {
        cout << n;
        return 0;
    }
    for (int i = 1; i < n; i++)
    {
        int cur = t[i + 1] - (t[i] + 1);
        peal.push_back(cur);
    }
    sort(peal.begin(), peal.end(), greater<int>());
    for (int i = 0; i < k - 1 and i < peal.size(); i++)
    {
        res -= peal[i];
    }
    cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...