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>
#define endline "\n"
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define lsb(i) i&(-i)
#define sz(i) (int)i.size()
typedef long long ll;
using namespace std;
const ll INF = 1e18L;
constexpr int mod = int(1e9) + 7;
ll t=1, n, k, cases = 0;
void solve(){
cin >> n >> k;
vector<ll> ar(n),sortar;
for(int i = 0; i < n; i++)cin >> ar[i];
for(int i = 0; i < n - 1; i++){
sortar.pb(ar[i + 1] - ar[i] - 1);
}
sort(sortar.begin(),sortar.end());
ll ans = n;
for(int i = 0; i < n - k; i++){
ans += sortar[i];
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
//cin>>t;
for(; cases < t; cases++)solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |