পৃষ্ঠাসমূহ

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

119 Greedy Gift Givers

import java.util.*;

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

        Scanner scanner = new Scanner(System.in);
        int counter = 0;
        while (scanner.hasNext()) {
            int people = scanner.nextInt();
            scanner.nextLine();
            counter++;
            Map<String, Integer> moneyToAll = new HashMap<>();
            String names = scanner.nextLine();
            String[] arr = names.split(" ");
            for (int i=0;i<people;i++) {
                moneyToAll.put(arr[i], 0);
            }

            for (int i=0;i<people;i++) {
                String who = scanner.next();
                int amount = scanner.nextInt();



                int number = scanner.nextInt();
                if (number != 0){
                    moneyToAll.replace(who, moneyToAll.get(who) - amount);
                    moneyToAll.replace(who, moneyToAll.get(who) + amount%number);
                }

                for (int j = 0; j< number; j++) {
                    String p = scanner.next();
                    moneyToAll.replace(p, moneyToAll.get(p) + amount/number);
                }

            }

            if (counter != 1) {
                System.out.println();
            }

            for (String anArr : arr) {
                System.out.println(anArr + " " + moneyToAll.get(anArr));
            }


        }
    }
}

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

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