結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー brthyyjpbrthyyjp
提出日時 2020-10-09 22:30:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 686 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 146,564 KB
最終ジャッジ日時 2023-09-27 18:21:52
合計ジャッジ時間 26,124 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,520 KB
testcase_01 AC 63 ms
71,444 KB
testcase_02 AC 66 ms
71,640 KB
testcase_03 AC 66 ms
71,408 KB
testcase_04 AC 65 ms
71,564 KB
testcase_05 AC 67 ms
71,464 KB
testcase_06 AC 65 ms
71,312 KB
testcase_07 AC 67 ms
71,664 KB
testcase_08 AC 66 ms
71,604 KB
testcase_09 AC 66 ms
71,528 KB
testcase_10 AC 66 ms
71,428 KB
testcase_11 AC 67 ms
71,524 KB
testcase_12 AC 66 ms
71,424 KB
testcase_13 AC 65 ms
71,548 KB
testcase_14 AC 68 ms
71,380 KB
testcase_15 AC 66 ms
71,552 KB
testcase_16 AC 68 ms
71,652 KB
testcase_17 AC 68 ms
71,572 KB
testcase_18 AC 603 ms
135,944 KB
testcase_19 AC 571 ms
142,516 KB
testcase_20 AC 373 ms
131,400 KB
testcase_21 AC 106 ms
78,860 KB
testcase_22 AC 395 ms
133,292 KB
testcase_23 AC 100 ms
77,936 KB
testcase_24 AC 485 ms
136,492 KB
testcase_25 AC 374 ms
124,888 KB
testcase_26 AC 171 ms
90,840 KB
testcase_27 AC 98 ms
78,268 KB
testcase_28 AC 612 ms
145,780 KB
testcase_29 AC 616 ms
145,992 KB
testcase_30 AC 607 ms
145,976 KB
testcase_31 AC 622 ms
145,872 KB
testcase_32 AC 642 ms
146,192 KB
testcase_33 AC 626 ms
146,188 KB
testcase_34 AC 674 ms
146,220 KB
testcase_35 AC 633 ms
145,860 KB
testcase_36 AC 673 ms
146,564 KB
testcase_37 AC 619 ms
145,828 KB
testcase_38 AC 622 ms
145,944 KB
testcase_39 AC 623 ms
145,860 KB
testcase_40 AC 618 ms
146,188 KB
testcase_41 AC 631 ms
146,028 KB
testcase_42 AC 686 ms
145,812 KB
testcase_43 AC 66 ms
71,476 KB
testcase_44 AC 68 ms
71,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

AB = []
for a, b in zip(A, B):
    AB.append((a, b))
AB.sort()
B_ = []
for _, b in AB:
    B_.append(b)

mab = []
for a, b in AB:
    mab.append(a*b)

from itertools import accumulate
cumb = [0]+B_
cumb = list(accumulate(cumb))

cumab = [0]+mab
cumab = list(accumulate(cumab))

m = 10**19
ans = -10**18
for i in range(n):
    x = AB[i][0]
    #temp1 = 0
    #for a, b in AB:
        #temp1 += b*abs(x-a)
    temp = 0
    temp = (cumb[i]-cumb[0]-cumb[n]+cumb[i])*x
    temp += -cumab[i]+cumab[0]+(cumab[n]-cumab[i])
    #print(x, temp1, temp)
    if temp <= m:
        ans = x
        m = temp
print(ans, m)
0