結果

問題 No.2601 Very Poor
ユーザー 👑 KA37RI
提出日時 2024-01-16 11:41:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 29,720 KB
最終ジャッジ日時 2024-09-30 06:39:37
合計ジャッジ時間 6,637 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, x, a):
	if n == 1:
		return a[0] if a[0] <= x else 0
			
	ans = 0
	r = 1
	s = 0
	for l in range(1, n - 1):
		while r < n - 1 and s + a[r] <= x:
			s += a[r]
			r += 1
		if s <= x:
			ans = max(s, ans)
		s -= a[l]
	
	r = 0
	s = sum(a)
	for l in range(n):
		while r < l and s + a[r] <= x:
			s += a[r]
			r += 1
		if s <= x:
			ans = max(s, ans)
		s -= a[l]
		
	return ans

n, x = [int(y) for y in input().split()]
a = [int(y) for y in input().split()]

print(solve(n, x, a))
0