Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 17 October 2022 [21:11]
- */
- #include <bits/stdc++.h>
- using namespace std;
- int a[100010];
- priority_queue<int > heap;
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int n,m,k;
- cin >> n >> m >> k;
- for(int i=1;i<=m;i++)
- cin >> a[i];
- int ans = (a[1]-1) + (n-a[m]);
- for(int i=2;i<=m;i++){
- if(a[i]-a[i-1]-1 == 0) continue;
- heap.push(a[i]-a[i-1]-1);
- }
- k--;
- while(k-- && !heap.empty()){
- ans+=heap.top();
- heap.pop();
- }
- cout << n-ans-m << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment