This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7;
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
ll n, k; cin >> n >> k; k--;
vector<ll> v; ll x; cin >> x;
ll last = 0, fifi = x;
for (ll i = 2; i <= n; i++) {ll xx; cin >> xx; v.pb(xx-x-1); x = last = xx;}
sort(v.begin(),v.end()); ll ans = last-fifi+1;
while (k--) {ans -= max(0LL,v.back()); v.pop_back();}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |