Blob's Apple Pies
InterviewTime limit1sMemory limit1024 MB
Given N positive integers arranged in a circle, find the maximum sum of K consecutive values, where the block may wrap around the end.
- Level
Easy3 of 10
- Topics
- Array, Sliding window, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Blob is hungry again today. So Blob went to the chef Yeonwoo and asked for something delicious.
Yeonwoo wanted to give the cute Blob the tastiest food possible, so Yeonwoo decided to make apple pie, the dish Yeonwoo makes best. Yeonwoo baked apple pies and arranged them on a table in a circle.
Each apple pie is represented by a positive integer, which denotes how tasty it is. (A larger number means a tastier apple pie.)

Blob wants to eat of the apple pies. Since Blob wants to eat without putting in any effort, Blob will eat apple pies that are placed consecutively.
Help Blob and find the maximum possible sum of the tastiness of the apple pies Blob will eat!
Input
The first line gives the number of apple pies and the number of apple pies Blob will eat, and , separated by a space.
The second line gives , the values denoting the tastiness of the apple pies, separated by spaces.
Output
Print the maximum possible sum of the tastiness of the apple pies Blob will eat.