# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1049761 | vjudge1 | Stove (JOI18_stove) | C++17 | 41 ms | 1480 KiB |
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;
#define ll long long
#define MAX 60 * 10000
void solve() {
int n,k;
cin >> n >> k;
vector <int> a(n);
vector <int> b;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n - 1; i++) {
b.push_back(a[i+1] - a[i]);
} sort(b.begin(),b.end());
if (k == 1) {
cout << a[n - 1] - a[0] + 1;
return;
} else if (n == k) {
cout << n ;
return;
}
int ans1 = a[n - 1] -a[0] + 1;
int ans = 0;
for (int i = 0; i < n - 1; i++) {
ans += b[i] + 1;
k--;
if (n - (i + 1)*2 <= k) {
ans += k;
break;
}
} cout << ans;
}
int main()
{
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |