package leetcode;

/**
 * https://leetcode.com/problems/sum-of-mutated-array-closest-to-target/
 */
public class Problem1300 {
    public int findBestValue(int[] arr, int target) {
        int max = 0;
        int sum = 0;
        for (int num : arr) {
            sum += num;
            max = Math.max(max, num);
        }
        int answer = sum / arr.length;
        return answer;
    }

    public static void main(String[] args) {
        Problem1300 prob = new Problem1300();
//        System.out.println(prob.findBestValue(new int[]{4,9,3}, 10)); // 3
//        System.out.println(prob.findBestValue(new int[]{2,3,5}, 10)); // 5
//        System.out.println(prob.findBestValue(new int[]{60864,25176,27249,21296,20204}, 56803)); // 11361
//        System.out.println(prob.findBestValue(new int[]{10,10,10}, 10)); // 3
//        System.out.println(prob.findBestValue(new int[]{1,1,1}, 10)); // 1
//        System.out.println(prob.findBestValue(new int[]{1,2,1}, 10)); // 2
        System.out.println(prob.findBestValue(new int[]{1,2,3}, 7)); // 3
    }
}

@@ -186,19 +186,19 @@
     int 
-max
+sum
  = 0;%0A  
@@ -199,35 +199,35 @@
  0;%0A        int 
-sum
+max
  = 0;%0A        fo
@@ -331,59 +331,726 @@
    i
-nt answer = sum / arr.length;%0A        return answer
+f (sum %3C= target) %7B%0A            return max;%0A        %7D%0A        int left = 1;%0A        int right = max;%0A        int mid;%0A        while (left %3C right) %7B%0A            mid = (left + right) / 2;%0A            sum = 0;%0A            for (int num : arr) %7B%0A                sum += (num %3E mid) ? mid : num;%0A            %7D%0A            if (sum %3E= target) %7B%0A                right = mid;%0A            %7D else %7B%0A                left = mid + 1;%0A            %7D%0A        %7D%0A        int sum1 = 0;%0A        int sum2 = 0;%0A        for (int num : arr) %7B%0A            sum1 += (num %3E left) ? (left) : num;%0A            sum2 += (num %3E left - 1) ? (left - 1) : num;%0A        %7D%0A        return (Math.abs(sum2 - target) %3C= Math.abs(sum1 - target)) ? left - 1 : left
 ;%0A  
@@ -1145,18 +1145,16 @@
 1300();%0A
-//
         
@@ -1212,34 +1212,32 @@
 ,3%7D, 10)); // 3%0A
-//
         System.o
@@ -1295,18 +1295,16 @@
 ); // 5%0A
-//
         
@@ -1401,18 +1401,16 @@
 / 11361%0A
-//
         
@@ -1479,18 +1479,16 @@
 ); // 3%0A
-//
         
@@ -1554,18 +1554,16 @@
 ); // 1%0A
-//
         

Update problem 1300