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> // PLEASE
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pp;
#define MAXN 300005
#define MAXM 1005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
int N, K;
ll V[MAXN];
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
vector <ll> difs;
cin >> N >> K;
ll ans = (ll)K;
for(int i=0; i<N; i++) cin >> V[i];
for(int i=0; i+1<N; i++) {
difs.PB(V[i+1]-V[i]);
ans += V[i+1] - V[i];
}
sort(difs.begin(), difs.end());
reverse(difs.begin(), difs.end());
for(int i=0; i<K-1; i++) ans -= difs[i];
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |