AmazonOA #357
Warehouse Robots with Threshold
估计中等可在线判题
Each robot has its own identity and is in exactly one state, running or waiting. A running robot requires the total number of running robots r≥its own threshold; a waiting robot requires the total number of waiting robots n−r to be strictly less than its own threshold. Find the number of valid identity configurations, without taking any modulus.
输入格式
The first line contains n and the second line contains n thresholds. The original bounds are 1≤n≤100000, 1≤a[i]≤n. The original int return signature cannot hold the actual result, so this site explicitly outputs an arbitrary-precision decimal integer of up to about 30103 digits.
输出格式
Output a single integer, the answer.
样例 1
输入:
2
1 2
输出:
2
样例 2
输入:
2
2 2
输出:
1
样例 3
输入:
3
2 2 2
输出:
4
样例说明
The outputs of the three public examples are 2; 1; and 4, checked by independent enumeration or direct simulation.