結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 Kazun
提出日時 2020-09-01 20:47:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 125,336 KB
最終ジャッジ日時 2024-07-20 06:22:34
合計ジャッジ時間 23,110 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(x):
    S=0
    for k in range(N):
        S+=B[k]*abs(x-A[k])
    return S

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

#===制約チェック
assert 1<=N<=2*10**5
assert len(A)==N
assert len(B)==N

for i in range(N):
    assert -10**6<=A[i]<=10**6
    assert 1<=B[i]<=10**6
#===

B_sum=sum(B)

L=[0]*N
for k in range(N):
    L[k]=(A[k],B[k])

L.sort(key=lambda x:x[0])

if B_sum%2:
    Med=(B_sum+1)//2
    Count=0

    for (X,Y) in L:
        Count+=Y
        if Med<=Count:
            break
    alpha=beta=X
else:
    alpha=beta=None

    Med=(B_sum+1)//2
    Count=0
    for (X,Y) in L:
        Count+=Y
        if Med<=Count and alpha==None:
            alpha=X
        if Med+1<=Count and beta==None:
            beta=X

print(alpha,beta,f(alpha))
0