# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
307210 | cpp219 | Stove (JOI18_stove) | C++14 | 22 ms | 1312 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.
// Solid <candgenesis>
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 3e5 + 4;
const ll inf = 1e9 + 7;
const ll base = 37;
typedef pair<ll,ll> LL;
ll n,k,a[N],i,b[N];
bool lf(ll x,ll y){
return x > y;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>k; k--;
for (i = 1;i <= n;i++) cin>>a[i];
for (i = 1;i < n;i++) b[i] = a[i + 1] - a[i] - 1;
sort(b + 1,b + n,lf);
ll ans = a[n] - a[1] + 1;
for (i = 1;i < n;i++){
if (k) ans -= b[i],k--;
else break;
}
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... |