結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー NoneNone
提出日時 2021-02-23 10:20:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,021 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 157,784 KB
最終ジャッジ日時 2023-10-22 05:09:10
合計ジャッジ時間 27,367 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,364 KB
testcase_01 AC 38 ms
53,372 KB
testcase_02 AC 39 ms
53,372 KB
testcase_03 AC 40 ms
53,364 KB
testcase_04 AC 38 ms
53,368 KB
testcase_05 AC 37 ms
53,368 KB
testcase_06 AC 38 ms
53,364 KB
testcase_07 AC 38 ms
53,368 KB
testcase_08 AC 39 ms
53,368 KB
testcase_09 AC 39 ms
53,368 KB
testcase_10 AC 38 ms
53,368 KB
testcase_11 AC 39 ms
53,368 KB
testcase_12 AC 39 ms
53,368 KB
testcase_13 AC 40 ms
53,364 KB
testcase_14 AC 39 ms
53,368 KB
testcase_15 AC 39 ms
53,364 KB
testcase_16 AC 39 ms
53,368 KB
testcase_17 AC 38 ms
53,364 KB
testcase_18 WA -
testcase_19 AC 609 ms
147,624 KB
testcase_20 AC 360 ms
113,288 KB
testcase_21 AC 86 ms
76,896 KB
testcase_22 AC 385 ms
115,832 KB
testcase_23 AC 80 ms
76,372 KB
testcase_24 AC 503 ms
141,684 KB
testcase_25 AC 371 ms
114,624 KB
testcase_26 AC 154 ms
90,268 KB
testcase_27 AC 78 ms
76,312 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 676 ms
157,452 KB
testcase_31 WA -
testcase_32 AC 670 ms
157,452 KB
testcase_33 AC 664 ms
157,456 KB
testcase_34 AC 670 ms
157,452 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 681 ms
157,460 KB
testcase_39 AC 668 ms
157,448 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 40 ms
53,252 KB
testcase_44 AC 39 ms
53,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Compress:
    def __init__(self,array):
        """ A=[(a,degeneracy),...] """
        S=[0]
        self.array=array[:]
        self.A=[]
        for a, cnt in array:
            S.append(S[-1]+cnt)
            self.A.append(a)
        self.S=S[1:]

    def __getitem__(self, i):
        j=bisect_left(self.S,i+1)
        return self.A[j]

    def sum(self, i):
        """ sum in [0,i) """
        j=bisect_left(self.S,i)
        res=0
        q=0
        for k in range(j):
            res+=self.A[k]*(self.S[k]-q)
            q=self.S[k]
        print(j, res)
        if j>0: res+=self.A[j]*(i-self.S[j-1])
        else: res+=self.A[j]*(i)
        return res

    def sort(self):
        S=[0]
        self.A=[]
        for a, cnt in sorted(self.array):
            S.append(S[-1]+cnt)
            self.A.append(a)
        self.S=S[1:]

    def __iter__(self):
        l=0
        for i in range(self.S[-1]):
            if i==self.S[l]:
                l+=1
            yield self.A[l]

    def __str__(self):
        return " ".join(list(map(str, self)))

def deg(A):
    """
    連続して続く文字を圧縮する(※Counterではない)
    [1,1,1,2,2,2,3] -> [(1,3),(2,3),(3,1)]
    """
    res=[]
    a0, cnt=A[0], 1
    for a in A[1:]:
        if a!=a0: res.append((a0,cnt)); cnt=1
        else: cnt+=1
        a0=a
    res.append((a0,cnt))
    return res

def median(array):
    L = len(array)
    if L%2==0:
        return (array[L//2-1]+array[L//2])/2
    else:
        return array[L//2]

###############################################################
import sys
from bisect import *
input = sys.stdin.readline

N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
data=[]
for a,b in zip(A,B):
    data.append((a,b))

C=Compress(data)

C.sort()

L=sum(B)
if L%2==0:
    X=(C[L//2-1]+C[L//2])/2
    res=0
    for i in range(N):
        res+=B[i]*abs(A[i]-X)
else:
    X=C[L//2]
    res=0
    for i in range(N):
        res+=B[i]*abs(A[i]-X)
print(X,round(res))
0