結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー |
![]() |
提出日時 | 2024-03-03 00:35:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 127 ms / 2,000 ms |
コード長 | 706 bytes |
コンパイル時間 | 439 ms |
コンパイル使用メモリ | 82,104 KB |
実行使用メモリ | 84,580 KB |
最終ジャッジ日時 | 2024-09-29 16:36:48 |
合計ジャッジ時間 | 3,491 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
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)