Robot Upgrades
Time limit1sMemory limit2048 MB
Count the ways to set each of N parts to an upgrade level from 0 to M so that, for each i, at most A_i parts reach level i or higher, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
The Kingdom of ICPC is under attack by evil balloons! Fortunately, Morgan the robot is ready to defend the kingdom. To strengthen his power, there are parts, numbered from to , that can be upgraded. Each part can be upgraded between and times, inclusive.
To save resources, Morgan's upgrades are subject to restrictions, numbered from to . For restriction , the number of parts upgraded at least times must not exceed .
Adrian is planning which upgrades to apply to Morgan and wonders how many upgrade configurations satisfy all the restrictions. Two configurations are different if and only if at least one part has a different number of upgrades. Since the answer can be large, find it modulo .
Input
The first line contains two integers and (, ). The next line contains integers (), given in non-increasing order, that is, .
Output
Output a single integer: the number of upgrade configurations that satisfy all restrictions, modulo .