GastonFontenla

Untitled

Sep 29th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int tc;
  10.     cin >> tc;
  11.  
  12.     while(tc--)
  13.     {
  14.         int n;
  15.         cin >> n;
  16.  
  17.         vector <long long> sumaFila(n, 0);
  18.         vector <long long> sumaColumna(n, 0);
  19.  
  20.         for(int i=0; i<n; i++)
  21.         {
  22.             for(int j=0; j<n; j++)
  23.             {
  24.                 long long a;
  25.                 cin >> a;
  26.                 sumaFila[i] += a;
  27.                 sumaColumna[j] += a;
  28.             }
  29.         }
  30.  
  31.         sort(sumaFila.begin(), sumaFila.end());
  32.         sort(sumaColumna.begin(), sumaColumna.end());
  33.  
  34.         bool posible = true;
  35.  
  36.         for(int i=0; i<n && posible; i++)
  37.             if(sumaFila[i] != sumaColumna[i])
  38.                 posible = false;
  39.  
  40.         if(posible)
  41.             cout << "Possible" << endl;
  42.         else
  43.             cout << "Impossible" << endl;
  44.     }
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment