#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <array>
using std::cin; using std::cout;
using std::max; using std::min;
using std::vector; using std::string;
using ll=long long;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
template<class T, class U> bool ckmin(T &a, U b){return (a>b? a=b, true : false);}
template<class T, class U> bool ckmax(T &a, U b){return (a<b? a=b, true: false);}
int main(){
ll n, k;
cin>>n>>k;
vector<ll> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
vector<ll> dif;
for(int i=1;i<n;i++){
dif.push_back(a[i]-a[i-1]-1);
}
sort(dif.rbegin(), dif.rend());
/* sort(a.begin(), a.end()); */
ll ans = a[n-1]-a[0]+1;
for(int i=0;i<k-1;i++){
ans-=dif[i];
}
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
6 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
6 ms |
256 KB |
Output is correct |
10 |
Correct |
7 ms |
512 KB |
Output is correct |
11 |
Correct |
7 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
512 KB |
Output is correct |
13 |
Correct |
7 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
512 KB |
Output is correct |
15 |
Correct |
7 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
6 ms |
256 KB |
Output is correct |
10 |
Correct |
7 ms |
512 KB |
Output is correct |
11 |
Correct |
7 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
512 KB |
Output is correct |
13 |
Correct |
7 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
512 KB |
Output is correct |
15 |
Correct |
7 ms |
384 KB |
Output is correct |
16 |
Correct |
73 ms |
3184 KB |
Output is correct |
17 |
Correct |
77 ms |
3312 KB |
Output is correct |
18 |
Correct |
74 ms |
3184 KB |
Output is correct |
19 |
Correct |
78 ms |
3176 KB |
Output is correct |
20 |
Correct |
75 ms |
3184 KB |
Output is correct |
21 |
Correct |
74 ms |
3184 KB |
Output is correct |
22 |
Correct |
75 ms |
3184 KB |
Output is correct |
23 |
Correct |
74 ms |
3184 KB |
Output is correct |
24 |
Correct |
74 ms |
3184 KB |
Output is correct |