-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProgram.cs
54 lines (41 loc) · 1.63 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
namespace Organizing_Containers_of_Balls {
class Program {
public static bool OrganizingContainers(int n, int[][] containers) {
int[] containersSize = new int[n];
int[] amountOfBallsPerType = new int[n];
for (int i = 0; i < n; i++) {
int containerSize = 0;
int amountOfBalls = 0;
for (int j = 0; j < n; j++) {
containerSize += containers[i][j];
amountOfBalls += containers[j][i];
}
containersSize[i] = containerSize;
amountOfBallsPerType[i] = amountOfBalls;
}
for (int i = 0; i < n; i++) {
bool match = false;
for (int j = 0; j < n; j++) {
if (containersSize[i] == amountOfBallsPerType[j]) {
match = true;
break;
}
}
if (!match)return false;
}
return true;
}
static void Main(string[] args) {
int q = Convert.ToInt32(Console.ReadLine().Trim());
for (int i = 0; i < q; i++) {
int n = Convert.ToInt32(Console.ReadLine().Trim());
int[][] container = new int[n][];
for (int j = 0; j < n; j++) {
container[j] = Array.ConvertAll(Console.ReadLine().Split(' '), containerTemp => Convert.ToInt32(containerTemp));
}
Console.WriteLine(OrganizingContainers(n, container) ? "Possible" : "Impossible");
}
}
}
}