結果

問題 No.1148 土偶Ⅲ
ユーザー roarisroaris
提出日時 2020-08-05 18:54:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 432 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 81,344 KB
実行使用メモリ 87,776 KB
最終ジャッジ日時 2023-10-17 10:30:06
合計ジャッジ時間 4,446 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,176 KB
testcase_01 AC 40 ms
53,176 KB
testcase_02 AC 40 ms
53,176 KB
testcase_03 AC 39 ms
53,176 KB
testcase_04 AC 39 ms
53,176 KB
testcase_05 AC 88 ms
79,140 KB
testcase_06 AC 96 ms
83,668 KB
testcase_07 AC 81 ms
77,636 KB
testcase_08 AC 93 ms
80,960 KB
testcase_09 AC 92 ms
81,668 KB
testcase_10 AC 82 ms
79,584 KB
testcase_11 AC 84 ms
77,492 KB
testcase_12 AC 48 ms
63,932 KB
testcase_13 AC 66 ms
72,696 KB
testcase_14 AC 58 ms
68,380 KB
testcase_15 AC 75 ms
76,484 KB
testcase_16 AC 61 ms
72,636 KB
testcase_17 AC 97 ms
87,776 KB
testcase_18 AC 57 ms
66,344 KB
testcase_19 AC 82 ms
80,368 KB
testcase_20 AC 70 ms
76,104 KB
testcase_21 AC 64 ms
76,028 KB
testcase_22 AC 55 ms
66,328 KB
testcase_23 AC 56 ms
70,344 KB
testcase_24 AC 59 ms
72,568 KB
testcase_25 AC 60 ms
72,588 KB
testcase_26 AC 78 ms
76,448 KB
testcase_27 AC 56 ms
68,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

n, w = map(int, input().split())
a = [int(input()) for _ in range(n)]
ans = 0
r = 0
now = 0
cnt = defaultdict(int)

for l in range(n):
    while r<n and now+a[r]<=w and cnt[a[r]]==0:
        now += a[r]
        cnt[a[r]] += 1
        r += 1
    
    ans = max(ans, r-l)
    
    if l==r:
        r += 1
    else:
        now -= a[l]
        cnt[a[l]] -= 1

print(ans)
0