Minimize replacements with values up to K to make sum of two given arrays equal

import java.util.*;
  
class GFG {
  
    
    
    
    public static int makeSumEqual(
        int[] a, int[] b, int K,
        int M, int N)
    {
        
        int sum1 = 0;
  
        
        int sum2 = 0;
  
        
        for (int el : a)
            sum1 += el;
  
        
        for (int el : b)
            sum2 += el;
  
        
        
        int diff = sum1 – sum2;
  
        
        
        int l1 = 0, r1 = M – 1;
  
        
        
        int l2 = 0, r2 = N – 1;
  
        
        int res = 0;
  
        
        
        Arrays.sort(a);
        Arrays.sort(b);
  
        
        
        while (l1