結果

問題 No.1251 絶対に間違ってはいけない最小化問題
コンテスト
ユーザー flippergo
提出日時 2026-03-21 10:59:41
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 501 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 169 ms
コンパイル使用メモリ 85,148 KB
実行使用メモリ 121,928 KB
最終ジャッジ日時 2026-03-21 10:59:56
合計ジャッジ時間 12,462 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
def f(x):
    tot = 0
    for i in range(N):
        tot += B[i]*abs(x-A[i])
    return tot
low = -10**6-10
high = 10**6+10
while high-low>1e-5:
    left = (2*low+high)/3
    right = (low+2*high)/3
    if f(right)>f(left):
        high = right
    else:
        low = left
r = f((low+2*high)/3)
l = f((2*low+high)/3)
if r>l:
    print(round((2*low+high)/3),round(l))
else:
    print(round((low+2*high)/3),round(r))
0