Created
July 29, 2025 09:13
-
-
Save inspirit941/09feccc8c9c3301eedd2b4684dbf7223 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python3 | |
| import math | |
| import os | |
| import random | |
| import re | |
| import sys | |
| # | |
| # Complete the 'organizingContainers' function below. | |
| # | |
| # The function is expected to return a STRING. | |
| # The function accepts 2D_INTEGER_ARRAY container as parameter. | |
| # | |
| def organizingContainers(container): | |
| counter = {} | |
| total_counter = {} | |
| for y in range(len(container)): | |
| counter[y] = {} | |
| for x in range(len(container[0])): | |
| counter[y][x] = container[y][x] | |
| if x not in total_counter: | |
| total_counter[x] = 0 | |
| total_counter[x] += container[y][x] | |
| min_type = min(total_counter.values()) | |
| min_container_length = math.inf | |
| for each_container in counter.values(): | |
| min_container_length = min(min_container_length, sum(each_container.values())) | |
| if min_type != min_container_length: | |
| return "Impossible" | |
| return "Possible" | |
| if __name__ == '__main__': | |
| fptr = open(os.environ['OUTPUT_PATH'], 'w') | |
| q = int(input().strip()) | |
| for q_itr in range(q): | |
| n = int(input().strip()) | |
| container = [] | |
| for _ in range(n): | |
| container.append(list(map(int, input().rstrip().split()))) | |
| result = organizingContainers(container) | |
| fptr.write(result + '\n') | |
| fptr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment