// Topcoder SRM 568 DIV 2, L2 BallsSeparating
// Topcoder SRM 566 DIV 2, L2 : PenguinPals
import java.util.*;
import java.math.*;
public class BallsSeparating {
public static void main(String[] args) {
System.out.println(
//
new BallsSeparating().minOperations(
new int[] { 75799, 268944, 342402 },
new int[] { 894352, 228640, 903885 },
new int[] { 908656, 414271, 292588 }
));
}
public int minOperations(int[] red, int[] green, int[] blue) {
int minOps = Integer.MAX_VALUE;
if (red.length < 3)
return -1;
int N = red.length;
for (int ir = 0; ir < N; ir++) {
for (int ig = 0; ig < N; ig++) {
if (ig == ir)
continue;
for (int ib = 0; ib < N; ib++) {
if (ib == ir || ib == ig)
continue;
int ops = 0;
ops += green[ir] + blue[ir];
ops += red[ig] + blue[ig];
ops += red[ib] + green[ib];
for (int ix = 0; ix < N; ix++) {
if (ix == ir || ix == ig || ix == ib)
continue;
int tot = red[ix] + green[ix] + blue[ix];
int max = Math.max(red[ix], Math.max(green[ix], blue[ix]));
ops += tot - max;
}
minOps = Math.min(minOps, ops);
}
}
}
return minOps;
}
}
No comments:
Post a Comment