結果

問題 No.1808 Fullgold Alchemist
ユーザー lam6er
提出日時 2025-03-20 21:15:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 750 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 107,100 KB
最終ジャッジ日時 2025-03-20 21:15:37
合計ジャッジ時間 3,686 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    M = int(input[1])
    A = list(map(int, input[2:2+N]))
    
    sum_A = sum(A)
    low = 0
    high = sum_A // M if M != 0 else 0  # Handle M=0 if needed, but constraints say M≥1
    
    ans = 0
    while low <= high:
        mid = (low + high) // 2
        required = mid * M
        s = 0
        possible = True
        for a in A:
            available = a + s
            if available < required:
                possible = False
                break
            s = available - required
        if possible:
            ans = mid
            low = mid + 1
        else:
            high = mid - 1
    print(ans)

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