পৃষ্ঠাসমূহ

রবিবার, ১৮ জুন, ২০১৭

661 Blowing Fuses

import java.util.*;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int counter = 0;
        while (scanner.hasNext()) {
            counter++;
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int c = scanner.nextInt();
            if (n == 0 && m == 0 & c == 0) break;
            int current = 0, flag = 0, max = 0;
            int[] capacity = new int[n+1];
            for (int i=1;i<=n;i++) {
                capacity[i] = scanner.nextInt();
            }

            int[] times = new int[n+1];
            for (int i=1;i<=m;i++) {
                int num = scanner.nextInt();
                times[num]++;
                if (times[num]%2 == 0) {
                    current -= capacity[num];
                } else {
                    current += capacity[num];
                    if (current > max) max = current;
                }
            }


            System.out.println("Sequence "+counter);
            if (max <= c) {
                System.out.println("Fuse was not blown.");
                System.out.println("Maximal power consumption was "+max+" amperes.");
            } else {
                System.out.println("Fuse was blown.");
            }

            System.out.println();

        }
    }
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন