結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 KazunKazun
提出日時 2020-08-16 17:04:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,384 KB
実行使用メモリ 124,940 KB
最終ジャッジ日時 2023-09-27 12:13:31
合計ジャッジ時間 19,430 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,496 KB
testcase_01 AC 61 ms
71,456 KB
testcase_02 AC 60 ms
71,592 KB
testcase_03 AC 61 ms
71,152 KB
testcase_04 AC 63 ms
71,308 KB
testcase_05 AC 62 ms
71,540 KB
testcase_06 AC 60 ms
71,464 KB
testcase_07 AC 59 ms
71,416 KB
testcase_08 AC 62 ms
71,640 KB
testcase_09 AC 63 ms
71,348 KB
testcase_10 AC 62 ms
71,308 KB
testcase_11 AC 61 ms
71,692 KB
testcase_12 AC 60 ms
71,312 KB
testcase_13 AC 58 ms
71,108 KB
testcase_14 AC 58 ms
71,572 KB
testcase_15 AC 59 ms
71,348 KB
testcase_16 AC 62 ms
71,600 KB
testcase_17 AC 61 ms
71,420 KB
testcase_18 AC 344 ms
124,940 KB
testcase_19 AC 331 ms
121,788 KB
testcase_20 AC 190 ms
101,028 KB
testcase_21 AC 82 ms
76,884 KB
testcase_22 AC 204 ms
100,032 KB
testcase_23 AC 78 ms
76,808 KB
testcase_24 AC 246 ms
104,076 KB
testcase_25 AC 197 ms
100,776 KB
testcase_26 AC 113 ms
87,136 KB
testcase_27 AC 84 ms
76,908 KB
testcase_28 AC 367 ms
123,872 KB
testcase_29 AC 360 ms
123,708 KB
testcase_30 AC 356 ms
123,932 KB
testcase_31 AC 364 ms
123,788 KB
testcase_32 AC 355 ms
124,032 KB
testcase_33 AC 388 ms
124,068 KB
testcase_34 AC 353 ms
124,192 KB
testcase_35 AC 343 ms
124,212 KB
testcase_36 AC 358 ms
123,868 KB
testcase_37 AC 352 ms
124,264 KB
testcase_38 AC 343 ms
124,028 KB
testcase_39 AC 348 ms
124,100 KB
testcase_40 AC 354 ms
124,056 KB
testcase_41 AC 343 ms
124,048 KB
testcase_42 AC 352 ms
123,996 KB
testcase_43 AC 61 ms
71,648 KB
testcase_44 AC 60 ms
71,364 KB
権限があれば一括ダウンロードができます

ソースコード

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**9<=A[i]<=10**9
    assert 1<=B[i]<=10**9
#===

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])

Med=(B_sum+1)//2
Count=0

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

print(X,f(X))

0