# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
559630 | joshjms | Stove (JOI18_stove) | C++17 | 25 ms | 3028 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 int long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << "\n";
const long long mod = 1e9 + 7;
int n, k, a[100005], ans;
vector <int> v;
void solve () {
cin >> n >> k;
k--;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(i > 1) v.pb(a[i] - a[i - 1] - 1);
}
ans = a[n] - a[1] + 1;
sort(v.begin(), v.end(), greater<int>());
for(int i = 0; i < k && i < v.size(); i++)
ans -= v[i];
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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... |