結果

問題 No.545 ママの大事な二人の子供
ユーザー titia
提出日時 2024-03-03 00:33:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 704 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 82,008 KB
実行使用メモリ 85,048 KB
最終ジャッジ日時 2024-09-29 16:36:27
合計ジャッジ時間 3,783 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect

n=int(input())

B=[list(map(int,input().split())) for i in range(n)]

B0=B[:n//2]
B1=B[n//2:]

X=[]
Y=[]

for i in range(1<<len(B0)):
    score=0

    for j in range(len(B0)):
        if i & (1<<j) != 0:
            score+=B0[j][0]
        else:
            score-=B0[j][1]

    X.append(score)


for i in range(1<<len(B1)):
    score=0

    for j in range(len(B1)):
        if i & (1<<j) != 0:
            score+=B1[j][0]
        else:
            score-=B1[j][1]

    Y.append(score)

X.sort()
Y.sort()

ind=len(Y)-1

ANS=1<<60

for i in range(len(X)):
    while ind-1>=0 and abs(X[i]+Y[ind])>abs(X[i]+Y[ind-1]):
        ind-=1

    ANS=min(ANS,abs(X[i]+Y[ind]))

print(ANS)
0