Codeforces Round #402 (Div. 2) 779C - Dishonest Sellers Solution


 

 Problem Link:  https://codeforces.com/problemset/problem/779/C

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. #define ll long long int
  10. int main() {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. ll n, k;
  14. cin >> n >> k;
  15. ll a[n + 1], b[n + 1], d[n + 1], ans = 0;
  16. for (int i = 0; i < n; i++) cin >> a[i];
  17. for (int i = 0; i < n; i++) {
  18. cin >> b[i];
  19. ans += b[i];
  20. d[i] = a[i] - b[i];
  21. }
  22. sort(d, d + n);
  23. for (int i = 0; i < k || d[i] <= 0; i++) {
  24. ans += d[i];
  25. }
  26. cout << ans << endl;
  27.  
  28. return 0;
  29. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.