結果

問題 No.1148 土偶Ⅲ
ユーザー rin204
提出日時 2022-03-23 15:35:44
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 354 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 191 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 82,688 KB
最終ジャッジ日時 2026-04-28 02:07:08
合計ジャッジ時間 3,699 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n, w = map(int, input().split())
A = [int(input()) for _ in range(n)] + [w + 1]
ans = 0
se = set()
r = 0
tot = 0
for l in range(n):
    while tot + A[r] <= w and A[r] not in se:
        se.add(A[r])
        tot += A[r]
        r += 1
    ans = max(ans, r - l)
    if l == r:
        r += 1
    else:
        se.remove(A[l])
        tot -= A[l]
print(ans)
0