#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
#define pp pop_back
#define int int64_t
#define sc second
#define fr first
using namespace std;
const int T=1e18+7, K=1e9+7;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k, i, p;
cin >> n >> k;
vector <int> v(n+1), s;
cin >> v[1];
for (i=2; i<=n; i++) {
cin >> v[i];
s.pb(v[i]-1-v[i-1]);
}
p=v[n]+1-v[1];
sort(s.rbegin(), s.rend());
for (i=0; i<k-1; i++) {
p-=s[i];
}
cout << p;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
544 KB |
Output is correct |
16 |
Correct |
15 ms |
2776 KB |
Output is correct |
17 |
Correct |
14 ms |
2916 KB |
Output is correct |
18 |
Correct |
14 ms |
3292 KB |
Output is correct |
19 |
Correct |
14 ms |
2888 KB |
Output is correct |
20 |
Correct |
14 ms |
3032 KB |
Output is correct |
21 |
Correct |
15 ms |
2892 KB |
Output is correct |
22 |
Correct |
14 ms |
3012 KB |
Output is correct |
23 |
Correct |
14 ms |
3036 KB |
Output is correct |
24 |
Correct |
14 ms |
3036 KB |
Output is correct |