Submission #784145

#TimeUsernameProblemLanguageResultExecution timeMemory
784145ArshiStove (JOI18_stove)C++17
100 / 100
31 ms5964 KiB
/**********************GOD**********************/

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <iterator>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll , ll> pll;

#define len                 length()
#define MP                  make_pair
#define fs                  first
#define sc                  second
#define pb(x)               push_back(x)
#define all(x)              x.begin() , x.end()
#define kill(x)             cout << x , exit(0)

const ll INF = 1e18 + 8;
const ll MOD = 1e9 + 7;
const ll MXN = 2e5 + 6;
const ll LOG = 28 - 5;

ll n , k , ans;
ll lst;

multiset<ll> st;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k;

    for(ll i = 0 ; i < n ; i ++) {
        ll x; cin >> x;
        if(i)
            st.insert(x - lst);
        lst = x;
    }

    for(ll i = 0 ; i < n - k ; i ++)
        ans += (*st.begin()) - 1 , st.erase(st.begin());

    cout << ans + n;

    return 0;
}

/*!
ahkh
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...