# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127220 | nhimnam120 | Stove (JOI18_stove) | C++14 | 28 ms | 1652 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>
#pragma optimize(Ofast)
using namespace std;
vector<int> inp;
vector<int> pro;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin >> n >> k;
for(int i=1;i<=n;i++){
int a;
cin >> a;
inp.push_back(a);
}
int 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);
}
}
int match=diff-k;
sort(pro.begin(),pro.end());
if(match<=0){
cout << n;
return 0;
}
int 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... |