結果

問題 No.1148 土偶Ⅲ
ユーザー H20
提出日時 2022-01-27 23:55:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 417 bytes
コンパイル時間 1,222 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 92,168 KB
最終ジャッジ日時 2024-12-26 08:29:32
合計ジャッジ時間 4,769 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

N,W = map(int, input().split())
A = []
for _ in range(N):
    A.append(int(input()))
D = collections.defaultdict(int)
ans = 0
j = 0
s = 0
for i in range(N+1):
    while j<N and s<=W and D[A[j]]==0:
        D[A[j]]=1
        s+=A[j]
        if s<=W:
            ans = max(ans,j-i+1)
        j += 1
    if i==N:
        break
    s -= A[i]
    D[A[i]]=0

if ans<=1:
    print(0)
else:
    print(ans)
0