# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42266 | RezwanArefin01 | Stove (JOI18_stove) | C++14 | 44 ms | 1528 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;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 1e5 + 10;
int a[maxn], n, k;
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
scanf("%d %d", &n, &k);
vector<int> v;
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if(i > 1) v.push_back(a[i - 1] - a[i]);
}
sort(v.begin(), v.end());
int ans = a[n] - a[1] + k;
for(int i = 0; i < k - 1; i++) ans += v[i];
cout << ans << endl;
}
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... |