TugOfWar/ ¶
~cpp
def inputWeights(n, weights):
for i in range(n):
weight = int(input())
weights.append(weight)
def reverseSort(list):
list.sort()
list.reverse()
def divideWeghts(n, weights):
group1 = 0
group2 = 0
for i in range(n):
if(group1 < group2):
group1 += weights[i]
else:
group2 += weights[i]
return (group1, group2)
if __name__ == '__main__':
weights = []
n = int(input())
inputWeights(n, weights)
reverseSort(weights)
groupsWeights = divideWeghts(n, weights)
print str(groupsWeights[0]) + ' ' + str(groupsWeights[1])
. 경 결 . --










