MAGCARI

Fixing

Oct 17th, 2022
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. /*
  2.     Task    : _example
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 17 October 2022 [21:11]
  6. */
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int a[100010];
  10. priority_queue<int > heap;
  11. int main()
  12. {
  13.     cin.tie(0)->sync_with_stdio(0);
  14.     cin.exceptions(cin.failbit);
  15.     int n,m,k;
  16.     cin >> n >> m >> k;
  17.     for(int i=1;i<=m;i++)
  18.         cin >> a[i];
  19.     int ans = (a[1]-1) + (n-a[m]);
  20.     for(int i=2;i<=m;i++){
  21.         if(a[i]-a[i-1]-1 == 0)  continue;
  22.         heap.push(a[i]-a[i-1]-1);
  23.     }
  24.     k--;
  25.     while(k-- && !heap.empty()){
  26.         ans+=heap.top();
  27.         heap.pop();
  28.     }
  29.     cout << n-ans-m << '\n';
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment