結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー r_ishidar_ishida
提出日時 2021-01-23 22:02:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 768 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 47,120 KB
最終ジャッジ日時 2023-08-30 06:14:28
合計ジャッジ時間 30,212 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,228 KB
testcase_01 AC 19 ms
8,140 KB
testcase_02 AC 16 ms
8,272 KB
testcase_03 AC 16 ms
7,776 KB
testcase_04 AC 16 ms
8,276 KB
testcase_05 AC 15 ms
8,212 KB
testcase_06 AC 16 ms
8,280 KB
testcase_07 AC 16 ms
8,164 KB
testcase_08 AC 16 ms
8,284 KB
testcase_09 AC 16 ms
8,204 KB
testcase_10 AC 16 ms
8,276 KB
testcase_11 AC 15 ms
8,280 KB
testcase_12 AC 15 ms
8,224 KB
testcase_13 AC 15 ms
8,280 KB
testcase_14 AC 16 ms
8,180 KB
testcase_15 AC 16 ms
8,268 KB
testcase_16 AC 16 ms
7,972 KB
testcase_17 AC 16 ms
8,216 KB
testcase_18 AC 693 ms
43,776 KB
testcase_19 AC 715 ms
42,628 KB
testcase_20 AC 356 ms
27,800 KB
testcase_21 AC 48 ms
10,968 KB
testcase_22 AC 397 ms
29,552 KB
testcase_23 AC 38 ms
10,516 KB
testcase_24 AC 527 ms
36,400 KB
testcase_25 AC 383 ms
28,884 KB
testcase_26 AC 121 ms
15,552 KB
testcase_27 AC 40 ms
10,608 KB
testcase_28 AC 745 ms
45,740 KB
testcase_29 AC 751 ms
47,056 KB
testcase_30 AC 762 ms
47,012 KB
testcase_31 AC 754 ms
47,120 KB
testcase_32 AC 768 ms
45,692 KB
testcase_33 AC 761 ms
45,652 KB
testcase_34 AC 765 ms
45,792 KB
testcase_35 AC 746 ms
45,112 KB
testcase_36 AC 746 ms
44,256 KB
testcase_37 AC 736 ms
45,768 KB
testcase_38 AC 748 ms
45,624 KB
testcase_39 AC 745 ms
45,548 KB
testcase_40 AC 757 ms
45,784 KB
testcase_41 AC 746 ms
45,788 KB
testcase_42 AC 736 ms
45,624 KB
testcase_43 AC 15 ms
8,284 KB
testcase_44 AC 16 ms
8,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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))
0