제출 #1313525

#제출 시각아이디문제언어결과실행 시간메모리
1313525thaibaotran555Stove (JOI18_stove)C++20
100 / 100
14 ms1468 KiB
///TRAN THAI BAO :3

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define maxN 100007

vector<int>gap;

int n, k;
int t[maxN];

void readData()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> t[i];
}

void solve()
{
    int ans = n;
    for(int i = 2; i <= n; i++)
        gap.push_back(t[i] - t[i-1]-1);
    sort(gap.begin(), gap.end());
    int j = 0;
    while(n > k)
    {
        ans += gap[j++];
        n--;
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    readData();
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...