Submission #757909

#TimeUsernameProblemLanguageResultExecution timeMemory
757909fdnfksdStove (JOI18_stove)C++14
100 / 100
26 ms3252 KiB

#include <bits/stdc++.h>

using namespace std;

const string taskname = "codeforces";
#define FILE 0

#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

#define bit(i, a) (((a)>>(i))&1)
#define ms(a, v) memset(a, v, sizeof(a))
#define lb(a, v) lower_bound(a.begin(), a.end(), v)
#define ub(a, v) upper_bound(a.begin(), a.end(), v)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<bool> vb;




const ll mod = 1e9+7;
const ll maxn = 2e5+13;
const ll inf = 1e9+5;
const ll infl = 1e18+5;
char tochar[] = {'0','1','2','3','4','5','6','7','8','9'};
const bool testcases = true;
const ll maxN=3e5+10;
ll n,a[maxN],k;
priority_queue<ll>pq;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//freopen((taskname+".inp").c_str(), "r", stdin);
	//freopen((taskname+".out").c_str(), "w", stdout);
    cin >> n >> k;
    for(int i=1;i<=n;i++) cin >> a[i];
    ll ans=a[n]+1-a[1];
    for(int i=1;i<n;i++)
    {
        pq.push(a[i+1]-a[i]-1);
    }
    k--;
    while(k--)
    {
        ans-=pq.top();
        pq.pop();
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...