#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;
template <typename T> inline void Read(T &x) {
char c = getchar();
bool f = false;
for (x = 0; !isdigit(c); c = getchar()) {
if (c == '-') {
f = true;
}
}
for (; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
}
if (f) {
x = -x;
}
}
template <typename T> inline bool CheckMax(T &a, const T &b) {
return a < b ? a = b, true : false;
}
template <typename T> inline bool CheckMin(T &a, const T &b) {
return a > b ? a = b, true : false;
}
const int N = 100005;
int n, m, ans, a[N], b[N];
int main() {
#ifdef wxh010910
freopen("d.in", "r", stdin);
#endif
Read(n), Read(m);
for (int i = 1; i <= n; ++i) {
Read(a[i]);
}
for (int i = 1; i < n; ++i) {
b[i] = a[i + 1] - a[i] - 1;
}
sort(b, b + n);
for (int i = 1; i <= n - m; ++i) {
ans += b[i];
}
printf("%d\n", ans + n);
#ifdef wxh010910
Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
1 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
580 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
1 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
580 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
800 KB |
Output is correct |
12 |
Correct |
3 ms |
832 KB |
Output is correct |
13 |
Correct |
2 ms |
880 KB |
Output is correct |
14 |
Correct |
2 ms |
928 KB |
Output is correct |
15 |
Correct |
2 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
1 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
580 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
800 KB |
Output is correct |
12 |
Correct |
3 ms |
832 KB |
Output is correct |
13 |
Correct |
2 ms |
880 KB |
Output is correct |
14 |
Correct |
2 ms |
928 KB |
Output is correct |
15 |
Correct |
2 ms |
960 KB |
Output is correct |
16 |
Correct |
20 ms |
2656 KB |
Output is correct |
17 |
Correct |
25 ms |
3620 KB |
Output is correct |
18 |
Correct |
27 ms |
4600 KB |
Output is correct |
19 |
Correct |
22 ms |
5564 KB |
Output is correct |
20 |
Correct |
21 ms |
6528 KB |
Output is correct |
21 |
Correct |
19 ms |
7492 KB |
Output is correct |
22 |
Correct |
22 ms |
8456 KB |
Output is correct |
23 |
Correct |
21 ms |
9420 KB |
Output is correct |
24 |
Correct |
20 ms |
10384 KB |
Output is correct |