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;
int n, k, x, v[100002], beg[100002];
set<pair<int, int> >s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
x = n;
for(int i = 1; i <= n; ++i)
cin >> v[i];
for(int i = 1; i <= n; ++i)
{
beg[i] = 1;
if(i < n)
s.insert({v[i+1] - v[i], i+1});
}
while(x > k)
{
pair<int, int> xx = *s.begin();
s.erase(xx);
beg[xx.second] = 0;
--x;
}
int cost = 0;
int lst = 0;
beg[n+1] = 1;
for(int i = 1; i <= n+1; ++i)
{
if(beg[i] == 1)
{
if(lst != 0)
{
cost = cost + v[i-1] - lst + 1;
lst = v[i];
}
else
lst = v[i];
}
}
cout << cost;
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... |