結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-10-09 22:57:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 86,652 KB
実行使用メモリ 109,292 KB
最終ジャッジ日時 2023-09-27 19:08:26
合計ジャッジ時間 21,512 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,144 KB
testcase_01 AC 63 ms
70,932 KB
testcase_02 AC 64 ms
75,324 KB
testcase_03 AC 65 ms
71,348 KB
testcase_04 AC 65 ms
74,696 KB
testcase_05 AC 67 ms
74,628 KB
testcase_06 AC 68 ms
75,108 KB
testcase_07 AC 64 ms
74,684 KB
testcase_08 AC 71 ms
75,480 KB
testcase_09 AC 69 ms
75,388 KB
testcase_10 AC 68 ms
75,460 KB
testcase_11 AC 70 ms
75,140 KB
testcase_12 AC 69 ms
75,292 KB
testcase_13 AC 66 ms
75,184 KB
testcase_14 AC 68 ms
75,412 KB
testcase_15 AC 67 ms
75,368 KB
testcase_16 AC 69 ms
75,364 KB
testcase_17 AC 71 ms
75,392 KB
testcase_18 AC 425 ms
108,432 KB
testcase_19 AC 415 ms
104,868 KB
testcase_20 AC 261 ms
100,396 KB
testcase_21 AC 98 ms
75,984 KB
testcase_22 AC 271 ms
98,148 KB
testcase_23 AC 91 ms
75,800 KB
testcase_24 AC 350 ms
104,620 KB
testcase_25 AC 275 ms
98,988 KB
testcase_26 AC 142 ms
84,464 KB
testcase_27 AC 94 ms
75,920 KB
testcase_28 AC 443 ms
108,960 KB
testcase_29 AC 433 ms
108,572 KB
testcase_30 AC 425 ms
108,988 KB
testcase_31 AC 440 ms
108,972 KB
testcase_32 AC 422 ms
108,996 KB
testcase_33 AC 450 ms
109,292 KB
testcase_34 AC 434 ms
109,040 KB
testcase_35 AC 440 ms
109,052 KB
testcase_36 AC 448 ms
109,044 KB
testcase_37 AC 439 ms
108,824 KB
testcase_38 AC 448 ms
109,276 KB
testcase_39 AC 440 ms
108,748 KB
testcase_40 AC 436 ms
109,052 KB
testcase_41 AC 428 ms
109,016 KB
testcase_42 AC 421 ms
109,048 KB
testcase_43 AC 67 ms
71,312 KB
testcase_44 AC 64 ms
75,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin

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

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

l = -1 * (10**9)
r = 10**9

while r-l > 3:

    m1 = (l*2+r)//3
    m2 = (l+r*2)//3

    if f(m1) <= f(m2):
        r = m2
    else:
        l = m1

ans = 0
for i in range(l-10,r+10):
    if f(ans) >= f(i):
        ans = i
print (ans,f(ans))
        
0