結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー |
![]() |
提出日時 | 2020-10-09 22:30:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 702 ms / 2,000 ms |
コード長 | 697 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 148,820 KB |
最終ジャッジ日時 | 2024-07-20 12:50:58 |
合計ジャッジ時間 | 25,951 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
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)