#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define rep2(i,a,b,c) for (int i=a;i<=b;i+=c)
#define rev(i,a,b) for (int i=a;i>=b;i--)
#define rev2(i,a,b,c) for (int i=a;i>=b;i-=c)
#define ii pair<ll,ll>
#define bit(i,j) ((i>>j)&1)
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define ll long long
#define F first
#define S second
#define sz(a) (int)(a.size())
#define on(n) __builtin_popcountll(n)
#define ld long double
#define __log2(x) 63-__builtin_clzll(x)
#define Mask(x) (1LL<<x)
#define ALL(v) v.begin(),v.end()
const int N=3e5+5;
const int mod=998244353;
int n,k,T[N];
void solution(){
cin >> n >> k;
rep(i,1,n) cin >> T[i];
ll res=T[n]-T[1]+1;
k--;
priority_queue<ll> pq;
rep(i,2,n) pq.push(T[i]-T[i-1]-1);
while(k--){
res-=pq.top();
pq.pop();
}
cout << res;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test=1;
//cin >> test;
while(test--)
solution();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
476 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
484 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
476 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
484 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
10 ms |
3160 KB |
Output is correct |
17 |
Correct |
10 ms |
2536 KB |
Output is correct |
18 |
Correct |
10 ms |
2780 KB |
Output is correct |
19 |
Correct |
12 ms |
2768 KB |
Output is correct |
20 |
Correct |
16 ms |
2780 KB |
Output is correct |
21 |
Correct |
18 ms |
2768 KB |
Output is correct |
22 |
Correct |
19 ms |
2768 KB |
Output is correct |
23 |
Correct |
21 ms |
2768 KB |
Output is correct |
24 |
Correct |
19 ms |
2768 KB |
Output is correct |