A Math Contest P14 - Choosing Marbles

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 2.0s
Memory limit: 512M

Author:
Problem type

There are M colours of marbles labelled from 1 to M with ai marbles of colour i (1iM). N people will each choose one marble, where no two people can choose the same colour marble. Find how many valid ways they can choose marbles, modulo 109+7.

Valid ways are considered different if at least one person takes a different marble, even of the same colour.

Constraints

1NM2×105

1ai109

Subtask 1 [5%]

1N2

Subtask 2 [15%]

1NM5×103

Subtask 3 [80%]

No additional constraints.

Input Specification

The first line contains two space-separated integers, N and M.

The next line contains M space-separated integers, a1,a2,,aM.

Output Specification

Output the number of valid ways to choose marbles, modulo 109+7.

Sample Input

Copy
2 3
1 2 1

Sample Output

Copy
10

Explanation for Sample

Let xi denote the i-th marble of colour 1, yi denote the i-th marble of colour 2, and zi denote the i-th marble of colour 3.

The ten ways for two people to choose marbles are:

  • x1,y1
  • x1,y2
  • x1,z1
  • y1,z1
  • y2,z1
  • y1,x1
  • y2,x1
  • z1,x1
  • z1,y1
  • z1,y2

Comments

There are no comments at the moment.