# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033628 | nathan4690 | Stove (JOI18_stove) | C++17 | 21 ms | 5212 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>
#define ll long long
#define ld long double
#define el cout << '\n'
#define f1(i,n) for(ll i=1;i<=n;i++)
#define __file_name ""
using namespace std;
const ll maxn = 1e6+5, inf=1e18;
ll n,k,a[maxn],b[maxn],s;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen(__file_name ".inp", "r")){
freopen(__file_name ".inp","r",stdin);
freopen(__file_name ".out","w",stdout);
}
// code here
cin >> n >> k;
f1(i,n) cin >> a[i];
f1(i,n-1){
b[i] = a[i+1] - a[i] - 1;
}
s = a[n] - a[1] + 1;
sort(b+1,b+n,greater<ll>());
f1(i,k-1) s -= b[i];
cout << s;
return 0;
}
/*
Code by: Nguyen Viet Trung Nhan
Cau Giay Secondary School
*/
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... |