# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1270961 | nthvn | Stove (JOI18_stove) | C++20 | 13 ms | 1096 KiB |
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define ll long long
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
const int N= 1e5+5;
int n,k;
int a[N], d[N];
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
if(fopen("STOVE.INP", "r")){
freopen("STOVE.INP", "r", stdin);
freopen("STOVE.OUT", "w", stdout);
}
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<n;i++) d[i] = a[i]-a[i+1];
sort(d+1,d+n);
ll ans = 0;
for(int i=1;i<=k-1;i++) ans+= d[i];
ans+= -a[1] + a[n]+k;
cout<<ans;
}
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... |