#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
//REF TE KUCUK ESITTIR YOK DIKKKKKKKKKKKKATTTTTT
#define ref(i,a,b) for (long long (i)=(a); (i)<(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pb push_back
#define mp make_pair
const unsigned int mod = 1e9+7;
const int mx=1e5+5;
int n,k;//ll or int ?
ll ans=1e17;
ll a[mx];
ll sub[mx-1];
/*void solve(ll v,ll kk,ll bitti,ll top){
if(v==(n-1) and kk==(k-1)){
// if(bitti)
ans=min(ans,top+1);
// else return;
}
else if(v==(n-1) and kk==k){
if(!bitti)
ans=min(ans,top);
else return;
}
if(v==(n-1))return;
if(kk>k)return;
if(bitti){
solve(v+1,kk+1,bitti,top+1);
solve(v+1,kk,1-bitti,top+sub[v]+1);
}
else{
solve(v+1,kk,bitti,top+sub[v]);//dikkat
solve(v+1,kk+1,1-bitti,top+1);
}
return;
}*/
int main(){
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> k;
rep(i,n)cin >> a[i];
ll ans=n;
int cc=0;
vector <int> wait;
ref(i,1,n){
if(!(a[i]==(a[i-1]+1))){
wait.pb(a[i]-a[i-1]-1);
++cc;
}
}
++cc;
sort(wait.begin(),wait.end());
for(int i=0;i<max(0,cc-k);++i)ans+=wait[i];
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
25 ms |
2680 KB |
Output is correct |
17 |
Correct |
25 ms |
2808 KB |
Output is correct |
18 |
Correct |
25 ms |
2808 KB |
Output is correct |
19 |
Correct |
31 ms |
2808 KB |
Output is correct |
20 |
Correct |
26 ms |
2680 KB |
Output is correct |
21 |
Correct |
26 ms |
2680 KB |
Output is correct |
22 |
Correct |
25 ms |
2680 KB |
Output is correct |
23 |
Correct |
26 ms |
2680 KB |
Output is correct |
24 |
Correct |
25 ms |
2808 KB |
Output is correct |