한국정보올림피아드 KOI 2019 1차대회 중등부 - 양팔문제

Problem

한국정보올림피아드 KOI 2019 1차대회 중등부 - 양팔문제

My solution

k = int(input()) gk = input() # k = '3' # gk = '1 2 6' gk_list = gk.split(' ') gk_list = [int(x) for x in gk_list] gk_list.sort() S = sum(gk_list) def func(gk_list): if len(gk_list) == 0: return 0 if len(gk_list) == 1: return gk_list pre_possible = func(gk_list[:-1]) sum_possible = [x + gk_list[-1] for x in pre_possible] minus_possible = [abs(gk_list[-1] - x) for x in pre_possible] new_possible = [gk_list[-1]] total_possible = pre_possible + sum_possible + minus_possible + new_possible result_list = [x for x in total_possible if x > 0] result_list = list(set(result_list)) return result_list answer = S - len(func(gk_list)) print(answer)

댓글