U E D R , A S I H C RSS

Tug Of War/신재동

No older revisions available

No older revisions available



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])

이전에 비스무리한 문제를 푼 적이 있었다. 하긴 이런류의 경시대회 문제들 어느 정도 풀다 보면 해결 방법이 몇 가지로 나뉘는 것 같다. --재동
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:18
Processing time 0.0502 sec