Codeforces Global Round 1 1110B - Tape Solution
Problem Link: https://codeforces.com/contest/1110/problem/B
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n, m, k;
- cin >> n >> m >> k;
- int b[n + 9] = {0}, a[n + 9] = {0};
- for (int i = 1; i <= n; i++) cin >> a[i];
- int ans = n;
- for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i] - 1;
- sort(b, b + n);
- for (int i = 1; i <= n - k; i++) ans += b[i];
- cout << ans << endl;
- }
No comments