Simple Problem
Time limit1sMemory limit1024 MB
Given p and a sequence b, decide whether some permutation of 1 to N makes the maximum residue-class count over each prefix equal b_i.
- Level
Medium6 of 10
- Topics
- Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
After leaving PULSE and entering graduate school, Sanjini is fishing at Taejongdae on a holiday, hoping to catch a big one. Hours pass with no bite. Sleepy from holding the rod for so long, Sanjini starts thinking about a simple sequence.
For a permutation of length , define and a sequence as follows.
- () is the number of elements among whose remainder modulo is ().
- () is the maximum of .
Sanjini thinks a little longer and wonders whether a permutation exists for a given and sequence . Determine whether a permutation that satisfies the conditions exists.
Input
The first line contains the length of sequence and the integer , separated by a space.
The second line contains the elements of sequence in order, separated by spaces.
Output
If a permutation that satisfies the conditions exists, print YES. Otherwise, print NO.
Hint
A permutation of length is a finite sequence in which each integer from 1 to is used exactly once. For example, is a permutation, but and are not.