HW7.17

时间:2022-12-07 03:26:05

HW7.17

HW7.17

 import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);

         int n = input.nextInt();
         int limit = input.nextInt();

         int[][] borrowers = new int[n][n];

         for(int i = 0; i < n; i++)
         {
             borrowers[i][i] = input.nextInt();
             int volume = input.nextInt();
             int[] temp = new int[volume * 2];
             for(int j = 0; j < temp.length; j++)
                 temp[j] = input.nextInt();
             for(int j = 1; j < temp.length; j += 2)
                 borrowers[i][temp[j - 1]] = temp[j];
         }

         boolean existChange = false;
         while(true)
         {
             existChange = false;
             for(int i = 0; i < n; i++)
             {
                 int sum = 0;
                 for(int j = 0; j < n; j++)
                     sum += borrowers[i][j];
                 if(sum < limit)
                 {
                     System.out.println("Unsafe Bank -- " + i);
                     existChange = true;
                     for(int j = 0; j < n; j++)
                         if(j != i)
                             borrowers[j][i] = 0;
                 }
             }
             if(existChange == false)
                 break;
         }
     }
 }

相关文章