Open srlee056 opened 6 months ago
## refactored by gpt
import sys
from itertools import combinations
def read_input():
input = sys.stdin.read().splitlines()
n = int(input[0])
arr = [list(map(int, line.split())) for line in input[1:n+1]]
return n, arr
def get_stat_diff(arr, team):
sum_team = 0
for i in team:
for j in team:
if i != j:
sum_team += arr[i][j]
return sum_team
def main():
n, arr = read_input()
# Create all possible combinations for one team
all_teams = list(combinations(range(n), n // 2))
mid_point = len(all_teams) // 2
min_diff = float('inf')
for i in range(mid_point):
team1 = all_teams[i]
team2 = all_teams[-1-i]
stat1 = get_stat_diff(arr, team1)
stat2 = get_stat_diff(arr, team2)
min_diff = min(min_diff, abs(stat1 - stat2))
print(min_diff)
if __name__ == "__main__":
main()
This issue was automatically generated from a commit.
Committed Files: