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 <queue>
#include <algorithm>
#include <utility>
#include <vector>
int n, k;
long long t[100005];
std::priority_queue <long long, std::vector <long long>, std::greater <long long> > pq;
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin >> n >> k;
for(int i = 1; i <= n; i++)
{
std::cin >> t[i];
}
for(int i = 1; i < n; i++)
{
pq.push(t[i + 1] - t[i] - 1);
}
long long ans = n;
for(int i = 1; i <= n - k; i++)
{
ans += pq.top();
pq.pop();
}
std::cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |