#include <bits/stdc++.h> // PLEASE
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pp;
#define MAXN 300005
#define MAXM 1005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
int N, K;
ll V[MAXN];
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
vector <ll> difs;
cin >> N >> K;
ll ans = (ll)K;
for(int i=0; i<N; i++) cin >> V[i];
for(int i=0; i+1<N; i++) {
difs.PB(V[i+1]-V[i]);
ans += V[i+1] - V[i];
}
sort(difs.begin(), difs.end());
reverse(difs.begin(), difs.end());
for(int i=0; i<K-1; i++) ans -= difs[i];
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
4 |
Correct |
2 ms |
528 KB |
Output is correct |
5 |
Correct |
2 ms |
528 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
4 |
Correct |
2 ms |
528 KB |
Output is correct |
5 |
Correct |
2 ms |
528 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
692 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
772 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
13 |
Correct |
2 ms |
880 KB |
Output is correct |
14 |
Correct |
3 ms |
928 KB |
Output is correct |
15 |
Correct |
3 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
4 |
Correct |
2 ms |
528 KB |
Output is correct |
5 |
Correct |
2 ms |
528 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
692 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
772 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
13 |
Correct |
2 ms |
880 KB |
Output is correct |
14 |
Correct |
3 ms |
928 KB |
Output is correct |
15 |
Correct |
3 ms |
960 KB |
Output is correct |
16 |
Correct |
25 ms |
3672 KB |
Output is correct |
17 |
Correct |
24 ms |
4768 KB |
Output is correct |
18 |
Correct |
25 ms |
5604 KB |
Output is correct |
19 |
Correct |
24 ms |
6568 KB |
Output is correct |
20 |
Correct |
25 ms |
7660 KB |
Output is correct |
21 |
Correct |
24 ms |
8496 KB |
Output is correct |
22 |
Correct |
26 ms |
9460 KB |
Output is correct |
23 |
Correct |
24 ms |
10424 KB |
Output is correct |
24 |
Correct |
25 ms |
11504 KB |
Output is correct |