結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー |
![]() |
提出日時 | 2020-10-09 22:16:09 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 699 ms / 2,000 ms |
コード長 | 514 bytes |
コンパイル時間 | 75 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 51,916 KB |
最終ジャッジ日時 | 2024-07-20 12:13:54 |
合計ジャッジ時間 | 23,568 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
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)