# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197349 | abil | Stove (JOI18_stove) | C++14 | 28 ms | 2356 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>
# define fr first
# define sc second
# define pb push_back
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
//# define int long long
using namespace std;
const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 7);
int a[N];
main()
{
int n, k;
cin >> n >> k;
vector<int > vec;
for(int i = 1;i <= n; i++){
scanf("%d", &a[i]);
}
for(int i = 2;i <= n; i++){
vec.pb(max((a[i]) - (a[i - 1] + 1),0));
}
sort(all(vec));
k--;
int ans = a[n] + 1 - a[1];
for(int i = vec.size() - 1;i >= 0; i--){
if(!k){
break;
}
k--;
ans -= vec[i];
}
cout << ans;
}
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... |