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>
#define MAX_N 100000
using namespace std;
int n, k;
int v[MAX_N + 1];
int d[MAX_N + 1];
int rez;
void readFile()
{
cin >> n >> k;
for(int i = 1; i <= n; i ++)
cin >> v[i];
}
void solve()
{
for(int i = 1; i < n; i ++)
d[i] = abs(v[i] - v[i + 1]);
sort(d + 1, d + n, greater<int>());
rez = min(n, k);
for(int i = k; i <= n; i ++)
rez += d[i];
}
void printFile()
{
cout << rez << "\n";
}
int main()
{
readFile();
solve();
printFile();
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... |