This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**********************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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |