#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> i;
int n, m, k, b[100001], tmp;
bool ck[100005];
vector<i> a;
int main(){
cin >> n >> k;
//cout << n << endl;
tmp = k;
for(int i = 1; i <= n; i++){
cin >> b[i];
//cout << b[i] << endl;
}
for(int i = 1; i < n; i++) a.push_back(make_pair(b[i + 1] - b[i], i));
sort(a.begin(), a.end());
//cout << ans << endl;
int cnt = n;
for(int i = 0; i < n - k; i++){
cnt += a[i].first - 1;
//cout << cnt << endl;
}
cout << cnt;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
508 KB |
Output is correct |
15 |
Correct |
5 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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
508 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
88 ms |
2800 KB |
Output is correct |
17 |
Correct |
87 ms |
2928 KB |
Output is correct |
18 |
Correct |
87 ms |
2824 KB |
Output is correct |
19 |
Correct |
87 ms |
2828 KB |
Output is correct |
20 |
Correct |
87 ms |
2928 KB |
Output is correct |
21 |
Correct |
87 ms |
2868 KB |
Output is correct |
22 |
Correct |
88 ms |
2928 KB |
Output is correct |
23 |
Correct |
87 ms |
2800 KB |
Output is correct |
24 |
Correct |
87 ms |
2800 KB |
Output is correct |