@@ -20,28 +20,24 @@ public int minCostToEqualizeArray(int[] nums, int cost1, int cost2) {
2020 sum += num ;
2121 }
2222 final int n = nums .length ;
23- long total = ( max * ( long ) n ) - sum ;
23+ long total = max * n - sum ;
2424 // When operation one is always better:
2525 if ((cost1 << 1 ) <= cost2 || n <= 2 ) {
26- return (int ) (( total * ( long ) cost1 ) % LMOD );
26+ return (int ) (total * cost1 % LMOD );
2727 }
2828 // When operation two is moderately better:
2929 long op1 = Math .max (0L , ((max - min ) << 1L ) - total );
3030 long op2 = total - op1 ;
31- long result = (( op1 + (op2 & 1L )) * ( long ) cost1 ) + (( op2 >> 1L ) * ( long ) cost2 ) ;
31+ long result = (op1 + (op2 & 1L )) * cost1 + (op2 >> 1L ) * cost2 ;
3232 // When operation two is significantly better:
33- total += op1 / (( long ) n - 2L ) * ( long ) n ;
34- op1 %= (( long ) n - 2L ) ;
33+ total += op1 / (n - 2L ) * n ;
34+ op1 %= n - 2L ;
3535 op2 = total - op1 ;
36- result =
37- Math .min (
38- result , ((op1 + (op2 & 1L )) * (long ) cost1 ) + ((op2 >> 1L ) * (long ) cost2 ));
36+ result = Math .min (result , (op1 + (op2 & 1L )) * cost1 + (op2 >> 1L ) * cost2 );
3937 // When operation two is always better:
4038 for (int i = 0 ; i < 2 ; ++i ) {
4139 total += n ;
42- result =
43- Math .min (
44- result , ((total & 1L ) * (long ) cost1 ) + ((total >> 1L ) * (long ) cost2 ));
40+ result = Math .min (result , (total & 1L ) * cost1 + (total >> 1L ) * cost2 );
4541 }
4642 return (int ) (result % LMOD );
4743 }
0 commit comments