// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
int d[123];
long long read() {
char ch = getchar();
while (ch < '0' || ch > '9') {
ch = getchar();
}
long long v = 0;
while ('0' <= ch && ch <= '9') {
v = v * 10 + (int) (ch - '0');
ch = getchar();
}
return v;
}
void write(int x) {
int len = 0;
while (x > 0) {
d[len++] = x % 10;
x /= 10;
}
for (int i = len - 1; i >= 0; i--) {
putchar('0' + d[i]);
}
if (len == 0) {
putchar('0');
}
putchar('\n');
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int N = read(), K = read();
vector<int> gaps;
int t; cin >> t;
int ans = -t;
for(int i = 1; i < N; i++) {
int x; cin >> x;
gaps.push_back(x-t-1);
t = x;
}
// for(auto x : gaps) cout << x << " ";
sort(rbegin(gaps), rend(gaps));
ans += t+1;
for(int i = 0; i < min(K-1, int(size(gaps))); i++) ans -= gaps[i];
write(ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |