#P13676. [GCPC 2023] Kaldorian Knights

[GCPC 2023] Kaldorian Knights

题目描述

The king of Kaldoria traditionally celebrates his birthday by inviting the knights of his realm to a big jousting tournament, and every noble house participates by sending their best knights to win fame and glory. At the end of the tournament, the king does not only choose a winner but ranks all nn knights from worst to best.

:::align{center} Painting of a medieval tournament, Codex Manesse. :::

The number of knights belonging to house ii is denoted by kik_i. Each knight serves at most one house. There can be knights who do not serve any house. The houses are ordered by their influence in the kingdom (with the first one being the most influential). If the k1k_1 knights of the most powerful house take the last k1k_1 places in the tournament, the house will incite a revolt against king and crown. The members of the second most influential house are not that powerful. Even if all its k2k_2 knights end up at the bottom of the ranking, it would be considered a strong provocation but the house would not be able to start a revolt. However, if the last k1+k2k_1 + k_2 places are taken by all the knights of the two most influential houses combined, then the two houses will unite and start fighting the king. More generally, if the knights of the \ell most powerful houses occupy the last k1+k2++kk_1 + k_2 + \dots + k_\ell places in the tournament, they will unite and incite a revolt.

Of course, a revolt has to be avoided at all cost. Knowing that the king often chooses the ranking spontaneously and without too much consideration, the chief mathematician of the crown has been tasked with analysing how many rankings will not lead to a revolt.

输入格式

The input consists of:

  • One line with integers nn (1n1061 \leq n \leq 10^6) and hh (0h50000 \leq h \leq 5000), the number of knights and the number of houses.
  • hh lines, with the iith line containing an integer kik_i (1kin1 \leq k_i \leq n), denoting the number of knights from house ii. Note that every house is represented by at least one knight.

It holds that i=1hkin\sum_{i=1}^h k_i \leq n.

输出格式

Output the number of rankings that do not lead to a revolt. As this number can be quite large, it should be output modulo 109+710^9+7.

3 0
6
4 1
3
18
4 2
2
1
16