#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
using namespace std;
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define vc vector
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define int ll
const int N = 1e5 + 5;
const int M = 1e5 + 5;
const int mod = 1e9 + 7;
const int block = 500;
int n, k, a[N];
void solve() {
cin >> n >> k;
ll ans = n;
for ( int i = 1; i <= n; i++ ) {
cin >> a[i];
}
vc <int> save, dist;
sort(all(a));
for ( int i = 1; i <= n; i++ ) {
if ( a[i] - a[i-1] <= 1 ) continue;
dist.pb(a[i]-a[i-1]-1);
save.pb(a[i]);
}
save.pb(a[n]);
if ( sz(save) <= k ) {
cout << ans;
return;
}
sort(all(dist));
int k2 = sz(save) - k;
for ( int i = 0; i < k2; i++ ) {
ans += dist[i];
}
cout << ans;
}
signed main() {
speed;
int tt;
//cin >> tt;
tt = 1;
while ( tt-- ) {
solve();
cout << '\n';
}
}
Compilation message
stove.cpp: In function 'void solve()':
stove.cpp:15:18: error: request for member 'begin' in 'a', which is of non-class type 'long long int [100005]'
15 | #define all(x) x.begin(),x.end()
| ^~~~~
stove.cpp:33:10: note: in expansion of macro 'all'
33 | sort(all(a));
| ^~~
stove.cpp:15:28: error: request for member 'end' in 'a', which is of non-class type 'long long int [100005]'
15 | #define all(x) x.begin(),x.end()
| ^~~
stove.cpp:33:10: note: in expansion of macro 'all'
33 | sort(all(a));
| ^~~