結果

問題 No.2601 Very Poor
ユーザー 👑 KA37RIKA37RI
提出日時 2024-01-16 11:30:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 743 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 31,984 KB
最終ジャッジ日時 2024-01-16 11:31:03
合計ジャッジ時間 7,996 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,984 KB
testcase_01 AC 29 ms
9,984 KB
testcase_02 AC 29 ms
9,984 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 31 ms
10,240 KB
testcase_06 AC 31 ms
10,240 KB
testcase_07 AC 31 ms
10,240 KB
testcase_08 AC 31 ms
10,240 KB
testcase_09 AC 32 ms
10,240 KB
testcase_10 AC 31 ms
10,240 KB
testcase_11 AC 31 ms
10,240 KB
testcase_12 AC 31 ms
10,240 KB
testcase_13 AC 32 ms
10,240 KB
testcase_14 AC 32 ms
10,240 KB
testcase_15 AC 255 ms
31,984 KB
testcase_16 AC 254 ms
31,984 KB
testcase_17 AC 232 ms
31,984 KB
testcase_18 AC 230 ms
31,984 KB
testcase_19 AC 232 ms
31,984 KB
testcase_20 AC 232 ms
31,984 KB
testcase_21 AC 233 ms
31,984 KB
testcase_22 AC 233 ms
31,984 KB
testcase_23 AC 230 ms
31,984 KB
testcase_24 AC 232 ms
31,984 KB
testcase_25 AC 231 ms
31,984 KB
testcase_26 AC 232 ms
31,984 KB
testcase_27 AC 234 ms
31,984 KB
testcase_28 AC 231 ms
31,984 KB
testcase_29 AC 230 ms
31,984 KB
testcase_30 AC 232 ms
31,984 KB
testcase_31 AC 232 ms
31,984 KB
testcase_32 AC 233 ms
31,984 KB
testcase_33 AC 231 ms
31,984 KB
testcase_34 AC 232 ms
31,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, x, a):
	if n == 1:
		return a[0] if a[0] <= x else 0
	elif n == 2:
		if a[0] + a[1] <= x:
			return a[0] + a[1]
		elif a[0] <= x and a[1] > x:
			return a[0]
		elif a[1] <= x and a[0] > x:
			return a[1]
		elif min(a[0], a[1]) > x:
			return 0
		else:
			return max(a[0], a[1])
			
	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
			# print(f"+{a[r]}")
		ans = max(s, ans)
		s -= a[l]
		# print(f"-{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