結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー titiatitia
提出日時 2020-10-09 23:35:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 561 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 40,952 KB
最終ジャッジ日時 2023-09-27 19:57:29
合計ジャッジ時間 33,504 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,716 KB
testcase_01 AC 16 ms
7,816 KB
testcase_02 AC 16 ms
7,748 KB
testcase_03 AC 15 ms
7,720 KB
testcase_04 AC 16 ms
7,864 KB
testcase_05 AC 16 ms
7,888 KB
testcase_06 AC 16 ms
7,828 KB
testcase_07 AC 16 ms
7,892 KB
testcase_08 AC 16 ms
7,828 KB
testcase_09 AC 16 ms
7,756 KB
testcase_10 AC 16 ms
7,820 KB
testcase_11 AC 16 ms
7,888 KB
testcase_12 AC 16 ms
7,680 KB
testcase_13 AC 15 ms
7,840 KB
testcase_14 AC 16 ms
7,868 KB
testcase_15 AC 16 ms
7,780 KB
testcase_16 AC 16 ms
7,812 KB
testcase_17 AC 16 ms
7,812 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 734 ms
24,580 KB
testcase_21 AC 99 ms
10,640 KB
testcase_22 AC 807 ms
26,124 KB
testcase_23 AC 72 ms
10,356 KB
testcase_24 AC 1,071 ms
32,776 KB
testcase_25 AC 792 ms
25,360 KB
testcase_26 AC 247 ms
14,140 KB
testcase_27 AC 75 ms
10,392 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1,521 ms
40,664 KB
testcase_31 WA -
testcase_32 AC 1,495 ms
40,724 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 1,494 ms
40,836 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1,511 ms
40,824 KB
testcase_43 AC 15 ms
7,676 KB
testcase_44 AC 16 ms
7,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

T=[(A[i],B[i]) for i in range(N)]
T.sort()

MIN=0
MAX=N-1

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

    return ANS

while MAX>MIN+1:
    mid=(MAX+MIN)//2

    d=calc(T[mid][0])
    u=calc(T[mid+1][0])

    if d<u:
        MAX=mid
    elif d>u:
        MIN=mid+1
    else:
        MIN=mid
        MAX=mid+1
        break

if calc(T[MIN][0])<=calc(T[MAX][0]):
    print(T[MIN][0],calc(T[MIN][0]))
else:
    print(T[MAX][0],calc(T[MAX][0]))
    
0