Rainbow Bowl Ranges

시간 제한2초메모리 제한2048 MB

요약
원형으로 놓인 n개의 그릇에 각 색의 공을 연속한 구간에 배치할 때, 모든 색을 담은 그릇이 이루는 극대 연속 구간의 수를 최대로 만든다.
난이도

보통10점 중 7점

유형
그리디, 수학, 구간, 구현
정답자
아직 제출이 없습니다

문제

You have a set of nn bowls, arranged in a circle.

You have many balls of various colors. There are mm different colors, and you have c_ic\_i balls of the i‘th‘i^`th` color.

You want to distribute all the balls into the bowls. To do this, for each color, you choose a contiguous range of bowls of size c_ic\_i and place one ball of that color in each bowl in the range. A contiguous range of bowls is a set of consecutive bowls around the circle. Ranges from different colors are allowed to overlap.

A bowl is rainbow if it contains one ball of each color. A rainbow bowl range is a contiguous range of rainbow bowls that cannot be extended by including another rainbow bowl.

You want to arrange balls in bowls to maximize the number of rainbow ranges.

Given the number of bowls and the number of balls of each color, what is the maximum number of rainbow bowl ranges that can be formed?

입력

The first line contains two integers, nn (2≤n≤109)(2 \le n \le 10^9), mm (1≤m≤105)(1 \le m \le 10^5).

The next mm lines each contain a single integer, c_ic\_i (1≤c_i≤n)(1 \le c\_i \le n).

출력

Print a single integer, the maximum number of rainbow bowl ranges that can be formed.

예제2

  1. 예제 1

    입력
    4 2
    3
    3
    
    예상 출력
    2
    
  2. 예제 2

    입력
    10 11
    3
    1
    4
    1
    5
    9
    2
    6
    5
    3
    5
    
    예상 출력
    1