#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
const ll N = 1e5+7;
ll n, m, ans = 0, a[N];
vector<ll> arr;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
f(i,1,n){
cin >> a[i];
}
ans += n;
sort(a+1, a+1+n);
ff(i,1,n){
arr.push_back(a[i+1] - a[i] - 1);
ans += a[i+1] - a[i] - 1;
}
sort(arr.begin(), arr.end(), less<ll>());
m-=1;
while(m && arr.size()){
ans -= arr.back();
m--;
arr.pop_back();
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
508 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
508 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
28 ms |
2932 KB |
Output is correct |
17 |
Correct |
28 ms |
2932 KB |
Output is correct |
18 |
Correct |
28 ms |
2936 KB |
Output is correct |
19 |
Correct |
28 ms |
2928 KB |
Output is correct |
20 |
Correct |
28 ms |
2932 KB |
Output is correct |
21 |
Correct |
28 ms |
2932 KB |
Output is correct |
22 |
Correct |
27 ms |
2936 KB |
Output is correct |
23 |
Correct |
28 ms |
2932 KB |
Output is correct |
24 |
Correct |
28 ms |
2932 KB |
Output is correct |