// In The Name Of God
#include <bits/stdc++.h>
#define sqr(A) ((A) * (A))
#define F first
#define S second
#define MP make_pair
#define bsz __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int N = 1e5 + 20;
int t[N], n, k, ans;
set<pair<int, pii> > s;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> t[i];
sort(t, t + n);
for (int i = 0; i < n - 1; i++)
s.insert(MP(t[i + 1] - t[i] - 1, MP(i, i + 1)));
k = n - k, ans = n;
while (k--) {
auto p = *s.begin();
ans += p.F;
s.erase(p);
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
480 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
580 KB |
Output is correct |
8 |
Correct |
2 ms |
584 KB |
Output is correct |
9 |
Correct |
2 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
480 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
580 KB |
Output is correct |
8 |
Correct |
2 ms |
584 KB |
Output is correct |
9 |
Correct |
2 ms |
648 KB |
Output is correct |
10 |
Correct |
3 ms |
780 KB |
Output is correct |
11 |
Correct |
3 ms |
940 KB |
Output is correct |
12 |
Correct |
3 ms |
988 KB |
Output is correct |
13 |
Correct |
4 ms |
1036 KB |
Output is correct |
14 |
Correct |
3 ms |
1084 KB |
Output is correct |
15 |
Correct |
3 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
480 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
580 KB |
Output is correct |
8 |
Correct |
2 ms |
584 KB |
Output is correct |
9 |
Correct |
2 ms |
648 KB |
Output is correct |
10 |
Correct |
3 ms |
780 KB |
Output is correct |
11 |
Correct |
3 ms |
940 KB |
Output is correct |
12 |
Correct |
3 ms |
988 KB |
Output is correct |
13 |
Correct |
4 ms |
1036 KB |
Output is correct |
14 |
Correct |
3 ms |
1084 KB |
Output is correct |
15 |
Correct |
3 ms |
1132 KB |
Output is correct |
16 |
Correct |
79 ms |
8460 KB |
Output is correct |
17 |
Correct |
76 ms |
9504 KB |
Output is correct |
18 |
Correct |
75 ms |
10516 KB |
Output is correct |
19 |
Correct |
78 ms |
11480 KB |
Output is correct |
20 |
Correct |
73 ms |
12444 KB |
Output is correct |
21 |
Correct |
72 ms |
13324 KB |
Output is correct |
22 |
Correct |
101 ms |
14264 KB |
Output is correct |
23 |
Correct |
73 ms |
15280 KB |
Output is correct |
24 |
Correct |
76 ms |
16300 KB |
Output is correct |