Rainbow Bowl Ranges
Time limit2sMemory limit2048 MB
Given n bowls in a circle and m colors with c_i balls each, place each color as a contiguous arc to maximize the number of maximal runs where every color appears exactly once.
Problem
There are bowls arranged in a circle.
There are many balls of various colors. There are different colors, and there are balls of the -th color.
Distribute all the balls into the bowls. For each color, choose a contiguous range of bowls of size and put one ball of that color into each bowl in the range. A contiguous range is a set of consecutive bowls around the circle. Ranges of different colors may overlap.
A bowl is rainbow if it contains exactly one ball of each color. A rainbow bowl range is a contiguous run of rainbow bowls that cannot be extended by adding another rainbow bowl.
Arrange the balls to maximize the number of rainbow bowl ranges. Given and the number of balls of each color, find the maximum number of rainbow bowl ranges that can be formed.
Input
The first line contains two integers and . Each of the next lines contains a single integer .
Output
Print a single integer, the maximum number of rainbow bowl ranges that can be formed.