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;
typedef long long ll;
const int N = 1e6 + 123,MOD = 1e9 + 7;
int n,k;
ll a[N],dp[5100][5100],mn[5100];
void test(){
cin >> n >> k;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
k--;
multiset<ll> st;
ll res = (a[n] - a[1] + 1);
for(int i = 1;i < n;i++){
st.insert(abs(a[i] - a[i + 1]) - 1);
}
while(k--){
ll val = (*st.rbegin());
res -= val;
st.erase(st.find(*st.rbegin()));
//cout << val << '\n';
}
cout << res;
}
int main(){
cin.tie(0);ios_base::sync_with_stdio(0);
int T = 1;
// cin >> T;
while(T--){
test();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |