fork download
  1. //NiceDuck
  2. #include "bits/stdc++.h"
  3. typedef long long ll;
  4. using namespace std;
  5. #define FILE "000"
  6. #define foru(i,a,b) for(int i=(int)(a); i<=(int)(b); ++i)
  7. #define ford(i,a,b) for(int i=(int)(a); i>=(int)(b); --i)
  8. #define fastio ios_base::sync_with_stdio(0);cin.tie(0);
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define pii pair<int,int>
  13. #define pil pair<int,ll>
  14. #define pli pair<ll,int>
  15. #define MOD 1000000007
  16. #define el "\n"
  17. #define MAX 200005
  18.  
  19. int n,k;
  20. struct Price
  21. {
  22. ll bef,aft,del;
  23. } p[MAX];
  24.  
  25. bool cmp(const Price &x, const Price &y)
  26. {
  27. return x.del>y.del;
  28. }
  29.  
  30. int main()
  31. {
  32. fastio
  33. #ifndef ONLINE_JUDGE
  34. freopen(FILE ".inp","r",stdin);
  35. freopen(FILE ".out","w",stdout);
  36. #endif // ONLINE_JUDGE
  37.  
  38. cin>>n>>k;
  39. foru(i,1,n)cin>>p[i].bef;
  40. foru(i,1,n)
  41. {
  42. cin>>p[i].aft;
  43. p[i].del=p[i].aft-p[i].bef;
  44. }
  45. sort(p+1,p+n+1,cmp);
  46. ll ans=0;
  47. foru(i,1,n)
  48. {
  49. if(i<=k) ans+=p[i].bef;
  50. else
  51. {
  52. if(p[i].del>=0) ans+=p[i].bef;
  53. else ans+=p[i].aft;
  54. }
  55. }
  56. cout<<ans;
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty