#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e5 + 5;
const int oo = 1e18, mod = 1e9 + 7;
int n, m, k, t[N];
string s;
vector<int> dist;
/*
sieu tom tat: dươc phep chon toi da k diem sao cho tong cua cac khoang cach
o cac diuem khong duoc chon la no nhat
liet ke ra k cac khoang cach giua 1 dong diem day
sort =)))
ok let's try
subtask 1: bitmask O(2^20)
subtask 2: dp (N*N)
subtask 3: greedy hoac la dp with data structure gi day
*/
void process() {
int res=t[n]-t[1]+1;
//cout << res << '\n';
foru(i,2,n) dist.pb(t[i]-t[i-1]);
sort(dist.begin(), dist.end(), greater<int>());
/*for (auto x: dist) cout << x << ' ';
cout << '\n';*/
foru(i,0,k-2) res-=(dist[i]-1);
cout << res;
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
cin >> n >> k;
foru(i,1,n) cin >> t[i];
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
756 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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
756 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 |
344 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 |
480 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
756 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 |
344 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 |
480 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
15 ms |
3292 KB |
Output is correct |
17 |
Correct |
15 ms |
3292 KB |
Output is correct |
18 |
Correct |
14 ms |
3292 KB |
Output is correct |
19 |
Correct |
14 ms |
3312 KB |
Output is correct |
20 |
Correct |
16 ms |
3308 KB |
Output is correct |
21 |
Correct |
15 ms |
3292 KB |
Output is correct |
22 |
Correct |
15 ms |
3292 KB |
Output is correct |
23 |
Correct |
14 ms |
3292 KB |
Output is correct |
24 |
Correct |
15 ms |
3292 KB |
Output is correct |