0
1

More than 1 year has passed since last update.

最大の区間和 Python3

Posted at

Python3の解答がなくて涙
何度も試行錯誤してやっと通過したので忘備録で残します

N,X = map(int,input().split())
A = list(map(int,input().split()))

S = [0]
max_num = 0
max_i = 0

for i in range(0,N):
    S.append(S[i] + A[i])

for i in range(0,N-X+1):
    if max_num < S[X+i] - S[i]:
        max_num = S[X+i] - S[i]
        max_i = i
print(max_num,A[max_i])
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1