제출 #966821

#제출 시각아이디문제언어결과실행 시간메모리
966821vjudge1Stove (JOI18_stove)C++17
100 / 100
21 ms2384 KiB
#include <bits/stdc++.h>
#define int long long
#define pii pair < int , int >
#define f first
#define s second

using namespace std;

const int inf = -1e18;

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

    int n , kib; cin >> n >> kib;
    priority_queue < int > q;

    int a[n];
    int cavab=n;
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
        if(i > 0)
        {
            cavab+=a[i]-(a[i-1]+1);
            q.push(a[i]-(a[i-1]+1));
        }
    }

    if(n==kib)
    {
        cout << n;
        return 0;
    }

    while(kib>1)
    {
        cavab-=q.top();
        q.pop();
        kib--;
    }
    cout << cavab;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...