# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52614 | snat123 | Stove (JOI18_stove) | C++14 | 30 ms | 11024 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;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k, res=0, cnt;
cin >> n >> k;
if(k==n){
cout << n;
return 0;
}
res=n;
cnt=n;
long long a[n];
for(int i=0; i<n; i++) cin >> a[i];
vector<int>v;
for(int i=1; i<n; i++){
v.push_back(a[i]-a[i-1]-1);
}
sort(v.begin(), v.end());
for(int i=0; i<v.size(); i++){
res+=v[i];
cnt--;
if(cnt==k) break;
}
cout << res;
return 0;
}
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... |