結果

問題 No.545 ママの大事な二人の子供
ユーザー convexineq
提出日時 2021-02-15 01:19:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 490 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 69,632 KB
最終ジャッジ日時 2024-07-22 13:07:45
合計ジャッジ時間 3,032 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

def sorted_subsetsum(a):
    A = [0]
    for ai in a:
        A *= 2
        for i in range(len(A)//2): A[i] += ai
        A.sort()
    return A

n = int(input())
v = 0
r = [0]*n
for i in range(n):
    a,b = map(int,input().split())
    r[i] = a+b
    v += b
p = sorted_subsetsum(r[:n//2])
q = sorted_subsetsum(r[n//2:])

ans = 1<<60
idx = len(q)-1
q.append(0)
for pi in p:
    while idx and pi+q[idx] >= v:
        idx -= 1
    ans = min(ans,abs(v-pi-q[idx]),abs(v-pi-q[idx+1]))
print(ans)
0