# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1109226 | codinion | Stove (JOI18_stove) | C++14 | 45 ms | 3792 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.
// https://oj.uz/problem/view/JOI18_stove
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
int N,K;
cin>>N;
cin>>K;
ll* gg = new ll[N];
for(int i=0;i<N;i++) {
cin>>gg[i];
}
sort(gg, gg+N);
vector<ll> active;
vector<ll> inactive;
ll totact = 0;
ll curract = 1;
for(int i = 1;i<N; i++) {
if(gg[i] - gg[i-1] == 1) {
curract++;
} else {
inactive.push_back(gg[i]-gg[i-1]-1);
active.push_back(curract);
totact+=curract;
curract = 1;
}
}
totact+=curract;
active.push_back(curract);
if(active.size() > K)
{
ll diff = active.size()-K;
sort(inactive.begin(), inactive.end());
for(ll i = 0;i<diff;i++)
totact += inactive[i];
}
cout<<totact<<endl;
}
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... |