# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127211 | nhimnam120 | Stove (JOI18_stove) | C++14 | 88 ms | 2812 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;
vector<long long> inp;
vector<long long> pro;
signed main(){
long long n,k;
cin >> n >> k;
for(int i=1;i<=n;i++){
long long a;
cin >> a;
inp.push_back(a);
}
long long diff=1;
sort(inp.begin(),inp.end());
for(int i=0;i<inp.size()-1;i++){
if(inp[i+1]-inp[i]>1){
diff++;
pro.push_back(inp[i+1]-inp[i]-1);
}
}
long long match=diff-k;
sort(pro.begin(),pro.end());
if(match<=0){
cout << n;
return 0;
}
long long ans=n;
for(int i=0;i<match;i++){
ans+=pro[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... |