Coins
InterviewTime limit1sMemory limit512 MB
Count the ways to place coins of sizes 1 to n into slots with capacities a_i so every coin fits, modulo 1000000007.
- Level
Medium4 of 10
- Topics
- Sorting, Combinatorics, Greedy
- Solved
- No attempts yet
Problem
Bajtazar is very proud of his collection of rare coins. He has gathered them over many years, making sure that no two are alike. He currently owns coins, numbered so that the -th coin has size exactly .
Because his collection has grown, Bajtazar bought a new coin album. It has exactly slots for coins, each with a fixed size. A coin cannot be placed in a slot that is too small for it, but it may be placed in a larger slot. Each slot holds exactly one coin, and every coin must be placed.
Bajtazar now wonders which slot to put each coin in, and in how many different ways he can fill the whole album. Because this number can be very large, it is enough to report it modulo . Write a program that computes this number.
Input
The first line contains one integer (). The second line contains integers () separated by single spaces. The value is the size of the largest coin that can be placed in the -th slot; that slot can therefore hold any coin whose size is at most .
Output
Print one integer: the number of ways to fill the album, modulo .