fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. static const int N = (int)1e5;
  5.  
  6. int n, k;
  7. int a[N], b[N];
  8. int p[N];
  9. long long ans;
  10.  
  11. bool comp(const int &x, const int &y) {
  12. return a[x] < a[y];
  13. }
  14.  
  15. int main() {
  16. freopen("input.txt", "rt", stdin);
  17. freopen("output.txt", "wt", stdout);
  18.  
  19. scanf("%d%d", &n, &k);
  20.  
  21. for (int i = 0; i < n; i++)
  22. scanf("%d", &a[i]), p[i] = i;
  23.  
  24. for (int i = 0; i < n; i++)
  25. scanf("%d", &b[i]);
  26.  
  27. std::sort(p, p + n, comp);
  28.  
  29. for (int i = 0; i < k; i++)
  30. ans += a[p[i]] - b[p[i]];
  31.  
  32. printf("%I64d", ans);
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 4636KB
stdin
Standard input is empty
stdout
Standard output is empty