結果
| 問題 | 
                            No.1251 絶対に間違ってはいけない最小化問題
                             | 
                    
| コンテスト | |
| ユーザー | 
                             norioc
                         | 
                    
| 提出日時 | 2024-06-20 05:07:05 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 495 bytes | 
| コンパイル時間 | 457 ms | 
| コンパイル使用メモリ | 82,256 KB | 
| 実行使用メモリ | 109,996 KB | 
| 最終ジャッジ日時 | 2024-06-20 05:07:28 | 
| 合計ジャッジ時間 | 22,477 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 | 
| other | WA * 42 | 
ソースコード
def ternary_search(f, lo, hi) -> float:
    l = lo
    r = hi
    for _ in range(100):
        c1 = (l * 2 + r) / 3
        c2 = (l + r * 2) / 3
        if f(c1) > f(c2):
            l = c1
        else:
            r = c2
    return l
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def f(x):
    res = 0
    for a, b in zip(A, B):
        res += b * abs(x - a)
    return res
lo = min(A)
hi = max(A)
x = ternary_search(f, lo, hi)
print(x, f(x))
            
            
            
        
            
norioc