#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m,ans = 0;
cin>>n>>m;
m--;
int a[n];
vector <pair<int,int>> b(n-1);
int bs[n-1];
cin>>a[0];
for(int k=1;k<n;k++){
cin>>a[k];
b[k-1].first = a[k] - a[k-1];
bs[k-1] = b[k-1].first;
}
sort(bs,bs+n-1);
int cnt = 0;
for(int k=0;k<n-1;k++){
if(b[k].first>=bs[n-m-1] and n-m-1<=n-2) {
cnt++;
b[k].second = 1;
} else b[k].second = 0;
}
if(cnt>m){
for(int k=0;k<n-1;k++){
if(b[k].first==bs[n-m-1] and cnt>m){
b[k].second = 0;
cnt--;
}
}
}
for(int k=0;k<n-1;k++){
int j = k;
if(b[k].second==1) ans++; else {
while(b[j].second!=1 and j<n-1){
ans = ans + b[j].first;
j++;
}
ans++;
k = j;
}
}
if(b[n-2].second==1) ans++;
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |