結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー wattaiheiwattaihei
提出日時 2020-10-09 22:16:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 687 ms / 2,000 ms
コード長 514 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 10,684 KB
実行使用メモリ 49,260 KB
最終ジャッジ日時 2023-09-27 17:50:48
合計ジャッジ時間 25,212 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,780 KB
testcase_01 AC 14 ms
7,756 KB
testcase_02 AC 15 ms
7,704 KB
testcase_03 AC 15 ms
7,756 KB
testcase_04 AC 14 ms
7,704 KB
testcase_05 AC 15 ms
7,784 KB
testcase_06 AC 15 ms
7,700 KB
testcase_07 AC 14 ms
7,896 KB
testcase_08 AC 15 ms
7,760 KB
testcase_09 AC 15 ms
7,756 KB
testcase_10 AC 15 ms
7,760 KB
testcase_11 AC 15 ms
7,844 KB
testcase_12 AC 15 ms
7,788 KB
testcase_13 AC 14 ms
7,788 KB
testcase_14 AC 14 ms
7,724 KB
testcase_15 AC 15 ms
7,840 KB
testcase_16 AC 14 ms
7,756 KB
testcase_17 AC 14 ms
7,728 KB
testcase_18 AC 650 ms
47,764 KB
testcase_19 AC 616 ms
46,956 KB
testcase_20 AC 331 ms
29,616 KB
testcase_21 AC 47 ms
11,092 KB
testcase_22 AC 334 ms
31,716 KB
testcase_23 AC 40 ms
10,380 KB
testcase_24 AC 477 ms
36,436 KB
testcase_25 AC 331 ms
30,228 KB
testcase_26 AC 110 ms
15,424 KB
testcase_27 AC 40 ms
10,564 KB
testcase_28 AC 676 ms
49,052 KB
testcase_29 AC 683 ms
49,136 KB
testcase_30 AC 655 ms
49,124 KB
testcase_31 AC 636 ms
49,164 KB
testcase_32 AC 679 ms
49,148 KB
testcase_33 AC 687 ms
49,132 KB
testcase_34 AC 683 ms
49,056 KB
testcase_35 AC 680 ms
49,068 KB
testcase_36 AC 659 ms
49,088 KB
testcase_37 AC 644 ms
49,220 KB
testcase_38 AC 682 ms
49,260 KB
testcase_39 AC 658 ms
49,064 KB
testcase_40 AC 643 ms
49,056 KB
testcase_41 AC 672 ms
49,084 KB
testcase_42 AC 685 ms
49,208 KB
testcase_43 AC 14 ms
7,700 KB
testcase_44 AC 16 ms
7,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline

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

dic = {}
for a, b in zip(A, B):
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b

AB = list(dic.items())
AB.sort()

bsum = sum(B) - 2*AB[0][1]
score = 0
pa = AB[0][0]
for a, b in AB:
    score += abs(pa-a) * b

a0, a1 = score, pa
for a, b in AB[1:]:
    score -= (a-pa)*bsum
    if a0 > score:
        a0, a1 = score, a
    bsum -= 2*b
    pa = a

print(a1, a0)
0