Morning Exercises
InterviewTime limit1sMemory limit1024 MB
Given a 2 x N pasture with some tree squares, find the longest run of tree-free columns and print twice its length.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
Each morning, Farmer John (FJ) leads his cows outside the barn for their morning calisthenics (fit cows give more milk). The cows must arrange themselves into two side-by-side lines of the same length. FJ has already set out a () strip of pasture for the exercises. Think of this strip as composed of grid squares. Just when he thought everything was ready, he realized that trees grow in some of these squares. Cows cannot stand on top of trees.
The cows must be grouped tightly together, so FJ cannot use other parts of the pasture. He has no choice but to split the cows into potentially multiple groups and conduct the exercises one group at a time. FJ likes conducting these exercises with larger groups of cows. Therefore, he wants to find the maximum number of cows he can take out into the pasture at once, while keeping in mind that the cows must occupy a contiguous sub-strip ().
Input
The first line contains an integer . Each of the next lines contains two space-separated integers that describe one strip of pasture. A square has a 1 if there is a tree in that square and a 0 if there is not.
Output
Print one integer, the number of cows that can participate in the exercise at once.