結果

問題 No.2601 Very Poor
ユーザー LyricalMaestro
提出日時 2025-05-01 15:32:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 482 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 113,228 KB
最終ジャッジ日時 2025-05-01 15:33:04
合計ジャッジ時間 5,868 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2601

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    if X >= sum(A):
        print(sum(A))
        return
    if X < min(A):
        print(0)
        return


    for i in range(N):
        if A[i] <= X:
            a1 = A[i:] + A[:i]
            A2 = a1 + a1
            break

    left = 0
    right = 0
    sums = A2[left]
    answer = sums
    while left < N:
        while right + 1 < 2 * N and A2[right + 1] + sums <= X:
            sums += A2[right + 1]
            right += 1
        
        answer = max(answer, sums)
        if left < right:
            sums -= A[left]
            left += 1
        else:
            left += 1
            right += 1
            while left < N and A2[left] > X:
                left += 1
                right += 1
            if left >= N:
                break
            else:
                sums = A2[left]
                answer = max(answer, sums)

    print(answer)













    



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