import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuffer sb = new StringBuffer(""); int ind=1; while (true) { String[] str = br.readLine().split(" "); int n = Integer.parseInt(str[0]); int m = Integer.parseInt(str[1]); int c = Integer.parseInt(str[2]); if (n == 0 && m == 0 && c == 0) { break; } boolean[] used = new boolean[n]; int[] cap = new int[n]; for (int i = 0; i < n; i++) { cap[i] = Integer.parseInt(br.readLine()); } int sum = 0, max = -1; boolean over = false; for (int i = 0; i < m; i++) { int index = Integer.parseInt(br.readLine())-1; if (!over) { if (!used[index]) { used[index] = true; sum += cap[index]; if (sum > max) { max = sum; } if (sum > c) { over = true; continue; } } else { used[index] = false; sum -= cap[index]; } } } sb.append("Sequence ").append(ind).append("\n"); if(over){ sb.append("Fuse was blown.").append("\n"); }else{ sb.append("Fuse was not blown.").append("\n"); sb.append("Maximal power consumption was ").append(max).append(" amperes.").append("\n"); } sb.append("\n"); ind++; } System.out.print(sb); } }
0 comments: