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?

paizaラーニング問題集「【全探索 1】高い寿司を食いたい!」を解いてみた

Posted at

▼考え方

連続するK枚の寿司の考え方について、以下に示します。

image.png

▼コード

########## 処理0(準備) インプット,リスト定義 ###########

N,K = map(int,input().split())

P = [0]*N
for i in range(N):
    P[i] = int(input())

# tmp_total: 連続するK枚の寿司の合計金額を格納する変数
tmp_total = 0

max_prime = 0

########## 処理1 連続するK枚の寿司の合計金額および最大値の計算、出力 ###########

for i in range(N):

    # j: 連続するK枚の寿司を走査する変数
    for j in range(i,i+K):
        if j > N-1:
            j -= N
        tmp_total += P[j]
    
    if tmp_total > max_prime:
        max_prime = tmp_total

    tmp_total = 0

print(max_prime)
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?