#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#define MOD 1000000007ll
#define EPS 1e-9
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pl;
typedef tuple <ll,ll,ll> tl;
ll N, K, T[100005], A;
vector <ll> gaps;
inline void read(ll& v) {
v = 0;
char ch = getchar_unlocked();
while (ch < '0' || ch > '9')
ch = getchar_unlocked();
while (ch >= '0' && ch <= '9') {
v = (v << 3) + (v << 1) + ch - '0';
ch = getchar_unlocked();
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
read(N);
read(K);
K = min(N, K);
for (ll i = 1; i <= N; i++) read(T[i]);
A = T[N] - T[1] + 1;
for (ll i = 2; i <= N; i++) gaps.push_back(T[i] - T[i-1] - 1);
sort(gaps.begin(), gaps.end(), greater<ll>());
for (ll i = 0; i < K-1; i++) A -= gaps[i];
cout << A;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
496 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
496 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
19 ms |
2292 KB |
Output is correct |
17 |
Correct |
18 ms |
2292 KB |
Output is correct |
18 |
Correct |
18 ms |
2292 KB |
Output is correct |
19 |
Correct |
18 ms |
2292 KB |
Output is correct |
20 |
Correct |
18 ms |
2292 KB |
Output is correct |
21 |
Correct |
19 ms |
2288 KB |
Output is correct |
22 |
Correct |
18 ms |
2292 KB |
Output is correct |
23 |
Correct |
18 ms |
2292 KB |
Output is correct |
24 |
Correct |
18 ms |
2292 KB |
Output is correct |