結果

問題 No.1211 円環はお断り
ユーザー Yatharth Singh
提出日時 2024-07-13 06:31:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 900 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 90,760 KB
最終ジャッジ日時 2024-07-13 06:32:04
合計ジャッジ時間 10,512 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other AC * 5 WA * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

def can_partition_with_max_sum(arr, N, K, max_sum):
    current_sum = 0
    sections = 0
    
    for i in range(2 * N):  # we iterate through the doubled array
        current_sum += arr[i % N]
        
        if current_sum > max_sum:
            sections += 1
            current_sum = arr[i % N]
            
            if sections >= K:
                return False
    
    return True

def minimize_max_section_value(N, K, arr):
    left = max(arr)
    right = sum(arr)
    
    while left < right:
        mid = (left + right) // 2
        
        if can_partition_with_max_sum(arr, N, K, mid):
            right = mid
        else:
            left = mid + 1
            
    return left

# Read input
N, K = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

# Output the minimized maximum value of the sections
print(minimize_max_section_value(N, K, arr))
0