結果

問題 No.837 Noelちゃんと星々2
ユーザー titiatitia
提出日時 2019-06-14 22:10:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,256 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 107,932 KB
最終ジャッジ日時 2023-08-09 01:03:50
合計ジャッジ時間 6,132 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 71 ms
71,240 KB
testcase_26 AC 71 ms
71,112 KB
testcase_27 WA -
testcase_28 AC 71 ms
71,540 KB
testcase_29 AC 69 ms
71,380 KB
testcase_30 AC 69 ms
71,320 KB
testcase_31 AC 72 ms
71,420 KB
testcase_32 AC 72 ms
71,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
Y=list(map(int,input().split()))

if max(Y)==min(Y):
    print(1)
    sys.exit()

Y.sort()

MIN=1
MAX=N-1

while True:
    x=(MIN+MAX)//2
    y=x+1

    B=Y[:x]
    C=Y[x:]

    SUM=sum(B)
    ANS=SUM
    LEN=len(B)
    NOW=0

    for i in range(LEN):
        SUM+=(B[i]-NOW)*i+(NOW-B[i])*(LEN-i)
        ANS=min(ANS,SUM)
        NOW=B[i]

    SUM=sum(C)
    ANS2=SUM
    LEN=len(C)
    NOW=0

    for i in range(LEN):
        SUM+=(C[i]-NOW)*i+(NOW-C[i])*(LEN-i)
        ANS2=min(ANS2,SUM)
        NOW=C[i]

    D=Y[:y]
    E=Y[y:]

    SUM=sum(D)
    ANS3=SUM
    LEN=len(D)
    NOW=0

    for i in range(LEN):
        SUM+=(D[i]-NOW)*i+(NOW-D[i])*(LEN-i)
        ANS3=min(ANS3,SUM)
        NOW=D[i]

    SUM=sum(E)
    ANS4=SUM
    LEN=len(E)
    NOW=0

    for i in range(LEN):
        SUM+=(E[i]-NOW)*i+(NOW-E[i])*(LEN-i)
        ANS4=min(ANS4,SUM)
        NOW=E[i]

    #print(x,y)
    #print(ANS,ANS2,ANS3,ANS4)

    if ANS+ANS2==ANS3+ANS4:
        print(ANS+ANS2)
        sys.exit()

    elif MAX==MIN:
        print(min(ANS+ANS2,ANS3+ANS4))
        sys.exit()
              

    elif ANS+ANS2<ANS3+ANS4:
        MAX=x
    else:
        MIN=y
        
    
        
        
    

    

    

0