Codeforces Global Round 1 1110B - Tape Solution



  Problem Link:   https://codeforces.com/contest/1110/problem/B

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int main() {
  10. int n, m, k;
  11. cin >> n >> m >> k;
  12. int b[n + 9] = {0}, a[n + 9] = {0};
  13. for (int i = 1; i <= n; i++) cin >> a[i];
  14. int ans = n;
  15. for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i] - 1;
  16. sort(b, b + n);
  17. for (int i = 1; i <= n - k; i++) ans += b[i];
  18. cout << ans << endl;
  19. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.