# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
708079 | yellowtoad | Stove (JOI18_stove) | C++17 | 63 ms | 4752 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 <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
int n, k, a[100010], ans;
pair<int,int> d[100010];
vector<int> b;
signed main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++) d[i] = {a[i+1]-a[i],i};
sort(d+1,d+n,greater<pair<int,int>>());
b.push_back(0);
for (int i = 1; i < k; i++) b.push_back(d[i].second);
b.push_back(n);
for (int i = 1; i < b.size(); i++) ans += a[b[i]]+1-a[b[i-1]+1];
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... |