#include<bits/stdc++.h>
using namespace std;
priority_queue<int> pq;
int a[111111];
int main()
{
int n,k;cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=2;i<=n;i++)
pq.push(a[i]-a[i-1]-1);
int ans=a[n];
int cnt=1;
while(cnt<k){
ans-=pq.top();
//cout<<pq.top()<<'\n';
pq.pop();
cnt++;
}
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |