fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8.  
  9. class Main
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. Scanner sc=new Scanner(System.in);
  15. int N=sc.nextInt();
  16. int X=sc.nextInt();
  17. int Y=sc.nextInt();
  18. int[] A=new int[N];
  19. int[] B=new int[N];
  20. int[] diff=new int[N];//difference of A[i]-B[i]
  21. int totalSum=0;
  22. for(int i=0;i<N;i++){
  23. A[i]=sc.nextInt();
  24. }
  25. for(int i=0;i<N;i++){
  26. B[i]=sc.nextInt();
  27. totalSum+=B[i];
  28. }
  29. //System.out.println("TotalSum = "+totalSum);
  30. for(int i=0;i<N;i++){
  31. int difference=A[i]-B[i];
  32. diff[i]=difference;
  33. }
  34. Arrays.sort(diff);
  35. int prevSum=totalSum;
  36. int maxSum=0;
  37. for(int x=1;x<=X;x++){
  38. prevSum=prevSum+diff[N-x];
  39. int y=N-x;
  40. if(y<=Y && (x+y)>=N) {
  41. //System.out.println("cycle = "+x);
  42. maxSum=Math.max(maxSum,prevSum);
  43. }
  44. }
  45. System.out.println(maxSum);
  46. sc.close();
  47. }
  48. }
  49.  
Success #stdin #stdout 0.17s 54664KB
stdin
5 3 3
1 2 3 4 5
5 4 3 2 1
stdout
21