Clap in a Row
InterviewTime limit2sMemory limit1024 MB
Given an N by M grid of clap counts, find the largest total clap count over any A consecutive columns spanning all rows.
- Level
Easy3 of 10
- Topics
- Prefix sum, Sliding window, Array
- Solved
- No attempts yet
Problem
Today is the day of the school festival that many students have been waiting for. As the festival coordinator, Bsil placed chairs in rows and columns in front of the stage, with one cheering squad member seated on each chair.
Bsil wants to check the cheering squad's morale by finding the spot with the most claps among consecutive columns. For columns 1 to , 2 to , 3 to , , and to , every member in the range claps. Then the largest clap count among these ranges is found.
Bsil has many duties as the festival coordinator, so Bsil left this job to us and went off to do other work.
Given the number of claps by each cheering squad member, find the clap count of the range that received the most claps.
Input
The first line contains integers and separated by a space.
The next lines describe the clap counts. Line contains separated by spaces, where is the clap count of the member in row , column .
Line contains , the number of columns chosen by Bsil.
Output
Print the clap count of the range that received the most claps.