結果

問題 No.1211 円環はお断り
ユーザー lam6er
提出日時 2025-04-09 21:01:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,067 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 96,152 KB
最終ジャッジ日時 2025-04-09 21:02:23
合計ジャッジ時間 4,748 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    K = int(input[1])
    A = list(map(int, input[2:2+N]))
    
    total = sum(A)
    
    if K > N:
        print(0)
        return
    
    if K == 0:
        print(0)
        return
    
    left = 1
    right = total // K
    ans = 0
    
    def can_achieve(M):
        if M == 0:
            return True
        count = 0
        current = 0
        for num in A:
            current += num
            if current >= M:
                count += 1
                current = 0
                if count >= K:
                    return True
        return False
    
    while left <= right:
        mid = (left + right) // 2
        max_a = max(A)
        if max_a < mid:
            right = mid - 1
            continue
        if total < K * mid:
            right = mid - 1
            continue
        if can_achieve(mid):
            ans = mid
            left = mid + 1
        else:
            right = mid - 1
    
    print(ans)

if __name__ == "__main__":
    main()
0