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 <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <stack>
#include <unordered_map>
using namespace std;
typedef long long ll;
struct triple {
ll a;
ll b;
ll c;
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k; cin >> n >> k;
vector<bool> os(1e9, false);
ll pren = n;
ll last = 0;
for(int i = 0; i < n; i++) {
ll t; cin >> t;
os[t-1] = true;
last = max(last, t);
}
vector<pair<ll,ll>> prze;
if(os[0]) {
prze.push_back({0, 1});
}
for(int i = 1; i < last + 1; i++) {
if(os[i]) {
if(os[i - 1]) {
prze[prze.size() - 1].second+=1;
} else {
prze.push_back({i, 1});
}
}
}
n = prze.size();
// ll st = n/k;
// ll nad = n%k;
vector<pair<ll, pair<ll,ll>>> diff(n - 1);
for(int i = 0; i < n - 1; i++) {
diff[i].first = prze[i + 1].first - prze[i].first - 1;
diff[i].second = {i, i + 1};
//cout << diff[i].first << " ";
}
sort(diff.begin(), diff.end(), [](pair<ll, pair<ll,ll>> a, pair<ll, pair<ll,ll>> b) {return a.first > b.first;});
ll dod = prze.size() - k;
ll wyn = pren;
for(int i = 0; i < dod; i++) {
wyn += diff[diff.size() - 1].first;
diff.pop_back();
}
cout << wyn;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |