結果

問題 No.615 集合に分けよう
ユーザー FromBooskaFromBooska
提出日時 2023-02-20 16:19:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 788 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 75,332 KB
最終ジャッジ日時 2023-09-28 13:51:38
合計ジャッジ時間 5,494 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,520 KB
testcase_01 AC 73 ms
71,012 KB
testcase_02 AC 77 ms
71,144 KB
testcase_03 AC 74 ms
71,224 KB
testcase_04 AC 75 ms
71,196 KB
testcase_05 AC 73 ms
71,376 KB
testcase_06 WA -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# Aをソートして二分探索

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def check(x):
    last = A[0]
    count = 1
    s = 0
    for i in range(N):
        if A[i] > last + x:
            s += A[i-1]-last
            last = A[i]
            count += 1
    s += A[N-1]-last
    return count, s

#for x in range(25):
#    print(x, check(x))
#print()

OK1 = 10**12+1
NG1 = -1
while (OK1-NG1)>1:
    mid = (OK1+NG1)//2
    if check(mid)[0] <= K:
        OK1 = mid
    else: 
        NG1 = mid
#print(OK1)

OK2 = 10**12+1
NG2 = -1
while (OK2-NG2)>1:
    mid = (OK2+NG2)//2
    if check(mid)[0] <= K-1:
        OK2 = mid
    else: 
        NG2 = mid
#print(OK2)

ans = 10**12
for i in range(OK1, OK2+1):
    ans = min(ans, check(i)[1])
print(ans)




0