Created
February 23, 2009 16:44
-
-
Save ioseb/69044 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ge.code.topcoder; | |
public class PowerOutage { | |
public int estimateTimeOut(int[] fromJunction, int[] toJunction, int[] ductLength) { | |
int[] sum = new int[50]; | |
int total = 0, max = 0; | |
for (int i = 0; i < fromJunction.length; i++) { | |
sum[toJunction[i]] = sum[fromJunction[i]] + ductLength[i]; | |
if (sum[toJunction[i]] > max) { | |
max = sum[toJunction[i]]; | |
} | |
total += ductLength[i]; | |
} | |
return 2 * total - max; | |
} | |
public static void main(String[] args) { | |
PowerOutage po = new PowerOutage(); | |
int result = po.estimateTimeOut( | |
new int[]{0,0,0,1,4,4,6,7,7,7,20}, | |
new int[]{1,3,4,2,5,6,7,20,9,10,31}, | |
new int[]{10,10,100,10,5,1,1,100,1,1,5} | |
); | |
System.out.println(result); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment