# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112665 | kzhi | Stove (JOI18_stove) | C++14 | 21 ms | 2300 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.
/*
Author : kmv a.k.a kzhi
K41 IT CHV
*/
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define FOR(i,a,b) for (int i = a ; i <= b; ++ i)
#define FOD(i,a,b) for (int i = a; i >= b; -- i)
#define BIT(mask,i) ((mask >> i) & 1)
#define MASK(i) (1ll << (i))
#define OFFBIT(mask,i) (mask &~(1ll<<(i)))
#define ONBIT(mask,i) (mask | (1ll << (i)))
#define lg2(x) (63 - __builtin_clzll(x))
#define c_bit __builtin_popcountll
#define vi vector < int >
#define all(a) a.begin(), a.end()
#define pb push_back
#define ii pair<int,int>
#define fi first
#define se second
#define openfile(TASK) if (fopen(TASK".inp","r"))\
{freopen(TASK".inp","r",stdin);freopen(TASK".out","w",stdout);}
#define endl '\n'
#define Faster ios_base::sync_with_stdio(false); \
cin.tie(0); cout.tie(0);
#define mid(l,r) ((l + r) >> 1)
#define left(id) (id << 1)
#define right(id) ((id << 1) | 1)
#define ci const int
template <class X, class Y> bool maximize(X &a, const Y &b){if(a < b) return a = b, true;return false;}
template <class X, class Y> bool minimize(X &a, const Y &b){if(a > b) return a = b, true;return false;}
const int N = 1e5 + 5;
int n, k;
int a[N];
int v[N];
void SOLVE(){
cin >> n >> k;
k --;
FOR (i, 1, n){
cin >> a[i];
if (i > 1)
v[i - 1] = a[i] - a[i - 1] - 1;
}
int res = a[n] + 1 - a[1];
sort(v + 1, v + n);
for (int i = 1; i <= k; i ++){
int pos = n - i;
if (pos <= 0)
break;
res -= v[pos];
}
cout << res;
}
signed main(){
Faster
openfile("stove")
int q = 1;
// cin >> q;
while (q --){
SOLVE();
}
return 0;
}
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... |