HW7.17

HW7.17

HW7.17

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8 
 9         int n = input.nextInt();
10         int limit = input.nextInt();
11 
12         int[][] borrowers = new int[n][n];
13         
14         for(int i = 0; i < n; i++)
15         {
16             borrowers[i][i] = input.nextInt();
17             int volume = input.nextInt();
18             int[] temp = new int[volume * 2];
19             for(int j = 0; j < temp.length; j++)
20                 temp[j] = input.nextInt();
21             for(int j = 1; j < temp.length; j += 2)
22                 borrowers[i][temp[j - 1]] = temp[j];
23         }
24 
25         boolean existChange = false;
26         while(true)
27         {
28             existChange = false;
29             for(int i = 0; i < n; i++)
30             {
31                 int sum = 0;
32                 for(int j = 0; j < n; j++)
33                     sum += borrowers[i][j];
34                 if(sum < limit)
35                 {
36                     System.out.println("Unsafe Bank -- " + i);
37                     existChange = true;
38                     for(int j = 0; j < n; j++)
39                         if(j != i)
40                             borrowers[j][i] = 0;
41                 }
42             }
43             if(existChange == false)
44                 break;
45         }
46     }
47 }