Codeforces Round #402 (Div. 2) 779C - Dishonest Sellers Solution
Problem Link: https://codeforces.com/problemset/problem/779/C
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;
- #define ll long long int
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- ll n, k;
- cin >> n >> k;
- ll a[n + 1], b[n + 1], d[n + 1], ans = 0;
- for (int i = 0; i < n; i++) cin >> a[i];
- for (int i = 0; i < n; i++) {
- cin >> b[i];
- ans += b[i];
- d[i] = a[i] - b[i];
- }
- sort(d, d + n);
- for (int i = 0; i < k || d[i] <= 0; i++) {
- ans += d[i];
- }
- cout << ans << endl;
- return 0;
- }
No comments