結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 KazunKazun
提出日時 2020-09-01 19:49:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 518 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 124,828 KB
最終ジャッジ日時 2023-09-27 12:14:14
合計ジャッジ時間 24,176 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,256 KB
testcase_01 AC 72 ms
71,460 KB
testcase_02 AC 72 ms
71,456 KB
testcase_03 AC 72 ms
71,336 KB
testcase_04 AC 73 ms
71,360 KB
testcase_05 AC 73 ms
71,388 KB
testcase_06 AC 75 ms
71,556 KB
testcase_07 AC 74 ms
71,540 KB
testcase_08 AC 74 ms
71,484 KB
testcase_09 AC 76 ms
71,568 KB
testcase_10 AC 73 ms
71,472 KB
testcase_11 AC 74 ms
71,380 KB
testcase_12 AC 74 ms
71,416 KB
testcase_13 AC 73 ms
71,500 KB
testcase_14 AC 76 ms
71,172 KB
testcase_15 AC 76 ms
71,260 KB
testcase_16 AC 73 ms
71,420 KB
testcase_17 AC 76 ms
71,316 KB
testcase_18 AC 425 ms
124,828 KB
testcase_19 AC 403 ms
121,264 KB
testcase_20 AC 229 ms
101,460 KB
testcase_21 AC 98 ms
76,656 KB
testcase_22 AC 238 ms
99,932 KB
testcase_23 AC 93 ms
76,448 KB
testcase_24 AC 300 ms
103,920 KB
testcase_25 AC 237 ms
100,672 KB
testcase_26 AC 134 ms
87,036 KB
testcase_27 AC 94 ms
76,784 KB
testcase_28 AC 433 ms
123,724 KB
testcase_29 AC 430 ms
123,664 KB
testcase_30 AC 422 ms
123,956 KB
testcase_31 AC 426 ms
123,436 KB
testcase_32 AC 430 ms
124,056 KB
testcase_33 AC 435 ms
123,932 KB
testcase_34 AC 429 ms
124,012 KB
testcase_35 AC 435 ms
123,692 KB
testcase_36 AC 442 ms
123,600 KB
testcase_37 AC 430 ms
123,976 KB
testcase_38 AC 427 ms
123,692 KB
testcase_39 AC 436 ms
123,768 KB
testcase_40 AC 431 ms
123,988 KB
testcase_41 AC 428 ms
123,924 KB
testcase_42 AC 430 ms
123,976 KB
testcase_43 AC 74 ms
71,336 KB
testcase_44 AC 73 ms
71,260 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**6<=A[i]<=10**6
    assert 1<=B[i]<=10**6
#===

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