fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define mset(arr,x) memset(arr,x,sizeof(arr))
  6. #define rep(i,s,e) for(i=s;i<=e;i++)
  7. #define rrep(i,s,e) for(i=s;i>=e;i--)
  8. #define min(a,b) ((a)<(b)?(a):(b))
  9. #define max(a,b) ((a)>(b)?(a):(b))
  10. #define pb push_back
  11. #define mp make_pair
  12. #define f first
  13. #define s second
  14. #define all(c) c.begin(),c.end()
  15.  
  16. vector< pair<ll ,ll> > vc;
  17. ll arr[2000010], barr[2000010];
  18. bool comp( pair<ll ,ll> pa1, pair<ll ,ll> pa2 )
  19. {
  20. return (pa1.f-pa1.s)<=(pa2.f-pa2.s);
  21. }
  22. int main()
  23. {
  24. ios_base::sync_with_stdio(false);
  25. cin.tie(0);
  26.  
  27. ll T, N, K, i, j, ans = 0;
  28. string st;
  29.  
  30. cin >> N >> K;
  31. rep(i, 1, N)
  32. {
  33. cin >> arr[i];
  34. }
  35. rep(i, 1, N)
  36. {
  37. cin >> barr[i];
  38. vc.pb( mp(arr[i], barr[i]) );
  39. }
  40. sort( all(vc), comp );
  41. rep(i, 0, K-1)
  42. {
  43. ans += vc[i].f;
  44. }
  45. rep(i, K, N-1)
  46. {
  47. if( vc[i].f<vc[i].s )
  48. {
  49. ans += vc[i].f;
  50. }
  51. else
  52. {
  53. ans += vc[i].s;
  54. }
  55. }
  56. cout << ans;
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 47312KB
stdin
3 1
5 4 6
3 1 5
stdout
10