Cherry Blossom Ending
InterviewTime limit3sMemory limit1024 MB
Given N cherry trees with bloom periods over M days, find the longest run of adjacent trees blooming together on any day and how many days reach that length.
- Level
Medium6 of 10
- Topics
- Segment tree, Sorting, Implementation
- Solved
- No attempts yet
Problem

Source: 윤찐빵
A cherry blossom festival to celebrate UDPC was held in UDP Village! The festival lasts days, and trees stand in a row at the festival site. The trees are numbered 1 to in order. The -th cherry tree blooms from day to day of the festival. Cherry blossoms look better when they are clustered, so Yoon, Dalgu, and Phoenix want to go flower viewing on a day when the most cherry trees are blooming in a row. On a given day, trees through are blooming in a row if all of them are in bloom that day. The number of cherry trees blooming in a row on a day is the maximum length over such intervals . For the three mascots who are looking forward to the festival, find the maximum number of cherry trees blooming in a row during the festival period, and the number of days on which that maximum occurs.
Input
The first line contains the number of cherry trees and the festival period , separated by a space. ()
From line 2 to line , line contains and , separated by a space, which give the period during which the -th cherry tree is in bloom. ()
Output
Print the maximum number of cherry trees blooming in a row during the festival period, and the number of days on which the most cherry trees are blooming in a row, separated by a space, in that order.