# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330743 | M_W | Stove (JOI18_stove) | C++14 | 1 ms | 364 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;
#define ii pair<int, int>
struct cmp{
bool operator()(const ii &a, const ii &b) const{
return abs(a.first - a.second) < abs(b.first - b.second);
}
};
int main(){
priority_queue<ii, vector<ii>, cmp> pq;
int N, K, cur, old, maxt = INT_MIN;
scanf("%d %d %d", &N, &K, &old);
for(int i = 1; i < N; i++){
scanf("%d", &cur);
pq.push(make_pair(old + 1, cur));
old = cur;
maxt = max(maxt, cur + 1);
}
K--;
vector<int> v;
while(!pq.empty() && K > 0){
int s = pq.top().first;
int e = pq.top().second;
pq.pop();
v.push_back(s);
v.push_back(e);
K--;
}
v.push_back(1);
v.push_back(maxt);
sort(v.begin(), v.end());
int sz = v.size();
int tuse = 0;
for(int i = 0; i < sz; i += 2){
tuse += v[i + 1] - v[i];
}
printf("%d", tuse);
}
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... |