結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
uni_python
|
| 提出日時 | 2020-10-10 11:43:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,730 ms / 2,000 ms |
| コード長 | 870 bytes |
| コンパイル時間 | 362 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 108,128 KB |
| 最終ジャッジ日時 | 2024-07-20 15:52:58 |
| 合計ジャッジ時間 | 43,422 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
N=I()
A=LI()
B=LI()
def calc(x):
res=0
for i in range(N):
res+=B[i]*abs(x-A[i])
return res
M=10**6+5
left=-M
right=M
for i in range(300):
c1=(2*left+right)//3
c2=(left+2*right)//3
if calc(c1)<calc(c2):
right=c2
else:
left=c1
aaa=int((right+left)//2)
ansx=aaa
ans=calc(aaa)
# for i in range(20):
# ii=i-10
# x=aaa+0.5*ii
# temp=calc(x)
# if temp<ans:
# ans=temp
# ansx=x
print(ansx,int(ans))
main()
uni_python