UVA661:

Blowing Fuses

import java.util.*;
import java.math.*;

public class Main{
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int counter = 1;

		while(sc.hasNextLine()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int c = sc.nextInt();


			if(n == 0 && m == 0 && c == 0){
				break;
			}


			int[] devices = new int[n]; 
			boolean[] switches = new boolean[n];
			int[] operations = new int[m];
			
 	
			for(int i = 0; i < n; i++){
				int x = sc.nextInt();
				devices[i] = x;
				switches[i] = true;

			}

			for(int i = 0; i < m; i++){
				int x = sc.nextInt();
				operations[i] = (x - 1);

			}


			
			boolean blown = false;
			int max = 0;
			int currCapacity = 0; 
			for(int i = 0; i < m; i++){
				int power = devices[operations[i]];

				if(switches[operations[i]]){
					currCapacity += power;
					switches[operations[i]] = !(switches[operations[i]]);

				} else {
					currCapacity -= power;
					switches[operations[i]] = !(switches[operations[i]]);
				}				

				if(currCapacity > max){
					max = currCapacity; 
				}

				if(currCapacity > c){
					blown = true;
				}

			}

			System.out.println("Sequence " + counter);
			counter++;

			if(blown){
				System.out.println("Fuse was blown.");

			} else {
				System.out.println("Fuse was not blown.");
				System.out.println("Maximal power consumption was " + max + " amperes.");

			}
		
			System.out.println("");

		}
	}
}
[Back to Listing Page]

Home

Posts

Projects

Github

Contact

janzzen

Developed by Janzzen Ang powered by Vercel