0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

連続する N 個の和の最大値】 連続する N 個の和の最大値 4 (paizaランク C 相当)

Posted at

連続する N 個の和の最大値】 連続する N 個の和の最大値 4 (paizaランク C 相当)

解答

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

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

s= [0]*(n+1)
m=0 
for i in range(n):
s[i+1]=s[i]+a[i] #累積和を求める式

for i in range((n+1)-k):
m=max(m,s[i+k]-s[i]) #大きい方を採用

print(m)

累積和を求めてから連続するk個の和の最大値を求めました。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?