Submission #481391

#TimeUsernameProblemLanguageResultExecution timeMemory
481391anjamilicevicStove (JOI18_stove)C++14
100 / 100
22 ms2064 KiB
#include <bits/stdc++.h>
#define IOS {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define MAXN 100005

int n, k, t[MAXN], d[MAXN];

using namespace std;

void solve()
{
    cin >> n >> k ;
    for(int i = 0 ; i < n ; i++)cin >> t[i] ;

    for(int i = 0 ; i < n-1 ; i++)
    {
        d[i] = t[i+1]-t[i]-1 ;
    }

    int rez = t[n-1]+1-t[0] ;

    sort(d,d+n-1);
    reverse(d,d+n-1);

    for(int i = 0 ; i < k-1 ; i++)
    {
        rez-=d[i];
    }

    cout << rez << endl ;
}

int main()
{
    IOS ;

    solve() ;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...