結果
| 問題 | No.545 ママの大事な二人の子供 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-10-31 23:01:23 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 116 ms / 2,000 ms | 
| コード長 | 513 bytes | 
| コンパイル時間 | 283 ms | 
| コンパイル使用メモリ | 82,428 KB | 
| 実行使用メモリ | 112,012 KB | 
| 最終ジャッジ日時 | 2024-07-08 10:39:31 | 
| 合計ジャッジ時間 | 3,654 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
ソースコード
from bisect import bisect_left
n = int(input())
lst = []
for _ in range(n):
    a, b = map(int, input().split())
    lst.append((a, b))
L = lst[:n//2]
R = lst[n//2:]
def f(A):
    ret = {0}
    for a, b in A:
        nex = set()
        for s in ret:
            nex.add(s + a)
            nex.add(s - b)
        ret = nex
    return sorted(ret)
L = f(L)
R = [-1 << 60] + f(R) + [1 << 60]
ans = 1 << 60
for l in L:
    l *= -1
    p = bisect_left(R, l)
    ans = min(ans, l - R[p - 1], R[p] - l)
print(ans)
            
            
            
        