fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. struct data{
  8. int x, y, z;
  9. };
  10.  
  11. int n, k, a[200005], b[200005];
  12. data f[200005];
  13.  
  14.  
  15. bool cmp(data d1, data d2){
  16. return (d1.x < d2.x);
  17. }
  18.  
  19.  
  20. int main(){
  21. cin >> n >> k;
  22. for (int i = 1; i <= n; i++){
  23. cin >> a[i];
  24. //cout << a[i] << " ";
  25. }
  26. // cout << endl;
  27. for (int i = 1; i <= n; i++){
  28. cin >> b[i];
  29. //cout << b[i] << " ";
  30. f[i].x = a[i]-b[i];
  31. f[i].y = a[i];
  32. f[i].z = b[i];
  33. }
  34. // cout << endl;
  35.  
  36. int res = 0;
  37. sort(f+1, f+n+1, cmp);
  38. for (int i = 1; i <= n; i++){
  39. if (i <= k) res+=f[i].y;
  40. else{
  41. if (f[i].x<=0) res+=f[i].y;
  42. else res+=f[i].z;
  43. }
  44. }
  45. // for (int i = 1; i <= n; i++){
  46. // cout << f[i].z << " ";
  47. // }
  48. // cout << endl;
  49. cout << res;
  50. return 0;
  51. }
Success #stdin #stdout 0s 19968KB
stdin
3 1
5 4 6
3 1 5
stdout
10