# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073326 | RKHTM | Stove (JOI18_stove) | C++14 | 17 ms | 3544 KiB |
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;
#define yasuho ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
const ll MOD = 1e9+7;
/*
1 2 5 6 8 11 13 15 16 20
1 3 1 2 3 2 2 1 4
^ ^ ^ ^
*/
void solve(){
ll n, k; cin >> n >> k;
vector<ll> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
ll ans = v.back()+1-v[1];
vector<ll> u;
for(int i=2; i<=n; i++){
u.push_back(v[i]-v[i-1]);
}
sort(u.begin(), u.end(), greater<ll>());
for(int i=0; i<u.size() and i<k-1; i++){
// cout << u[i] << ' ';
ans -= u[i]-1;
}
cout << ans << endl;
return;
}
int main(){
yasuho // remove for interactive problem
ll t;
t = 1;
//cin >> t;
while(t--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |