This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define all(v) (v).begin(),(v).end()
using namespace std;
const int N = 100005;
int a[N];
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector <int> difs;
for (int i = 2; i <= n; i++) {
difs.pb(a[i] - a[i - 1]);
}
sort(all(difs));
int res = k;
for (int i = 0; i < n - k; i++) {
res += difs[i];
}
cout << res << endl;
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... |