結果

問題 No.1211 円環はお断り
ユーザー gew1fw
提出日時 2025-06-12 21:43:56
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,179 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 81,732 KB
実行使用メモリ 91,100 KB
最終ジャッジ日時 2025-06-12 21:48:17
合計ジャッジ時間 4,416 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other AC * 13 TLE * 1 -- * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def max_min_value():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    total = sum(A)
    if K == 0:
        print(0)
        return
    if K == 1:
        print(total)
        return
    if K > N:
        print(0)
        return

    left = 0
    right = total // K + 1
    best = 0

    B = A + A
    prefix = [0] * (len(B) + 1)
    for i in range(len(B)):
        prefix[i+1] = prefix[i] + B[i]

    def is_possible(M):
        if M * K > total:
            return False
        for i in range(N):
            current_sum = 0
            count = 0
            for j in range(i, i + N):
                current_sum += B[j]
                if current_sum >= M:
                    count += 1
                    current_sum = 0
                    if count == K:
                        return True
            if current_sum == 0 and count >= K:
                return True
        return False

    while left <= right:
        mid = (left + right) // 2
        if is_possible(mid):
            best = mid
            left = mid + 1
        else:
            right = mid - 1
    print(best)

max_min_value()
0