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;
const int MAXN = 5003;
int n, k;
int times[MAXN];
void opt()
{
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
}
int main()
{
opt();
cin>>n>>k;
for (int i = 0; i < n; i++)
{
cin>>times[i];
}
int resp = n;
vector <int> difs;
for (int i = 1; i < n; i++)
{
difs.push_back(times[i] - times[i-1] -1);
}
sort(difs.begin(), difs.end());
for (int i = 0; i < n - k; i++)
{
resp += difs[i];
}
cout<<resp<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |