fork download
  1. import java.util.*;
  2.  
  3. class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6.  
  7. int n = sc.nextInt(); // number of orders
  8. int x = sc.nextInt(); // max Andy can take
  9. int y = sc.nextInt(); // max Bob can take
  10.  
  11. int[] a = new int[n]; // tips if Andy delivers
  12. int[] b = new int[n]; // tips if Bob delivers
  13. int[] diff = new int[n]; // a[i] - b[i]
  14.  
  15. long sum=0;
  16. for (int i = 0; i < n; i++) {
  17. a[i] = sc.nextInt();
  18. }
  19. for (int i = 0; i < n; i++) {
  20. b[i] = sc.nextInt();
  21. diff[i] = a[i] - b[i];
  22. }
  23.  
  24. for (int i = 0; i < n; i++) {
  25. if(x > 0 && a[i] > b[i]){
  26. sum += a[i];
  27. x--;
  28. } else {
  29. sum += b[i];
  30. y--;
  31. }
  32. }
  33. System.out.println(sum);
  34. }
  35.  
  36. }
Success #stdin #stdout 0.14s 56640KB
stdin
5 3 3
1 2 3 4 5
5 4 3 2 1
stdout
21