結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー | r_ishida |
提出日時 | 2021-01-23 22:02:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 846 ms / 2,000 ms |
コード長 | 856 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 48,160 KB |
最終ジャッジ日時 | 2024-12-31 18:15:24 |
合計ジャッジ時間 | 29,496 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
import sys def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) C=[[A[i],B[i]] for i in range(N)] if N==1: print(0,0) exit() sumB=sum(B) C.sort(key=lambda x:x[0]) temp=0 for index in range(N-1): temp+=C[index][1] if temp>=sumB/2: break X=[(C[index][0]+C[index+1][0])/2] if temp==sumB/2 else [C[index][0],C[index-1][0]] log=0 ans=10**18 for x in X: temp=0 for a,b in C: temp+=abs(x-a)*b if ans>=temp: ans=temp log=x print(log,int(ans))