Potato Shuffle
Time limit1sMemory limit512 MB
Count the distinct bag arrangements reachable by swapping adjacent bags whose potato total is at most k, modulo 1000000007.
- Level
Medium7 of 10
- Topics
- Array, Combinatorics, Sorting
- Solved
- No attempts yet
Problem
Marichka keeps a lot of potatoes in her basement. There are n bags of potatoes in a line, and the i-th bag contains a_i potatoes.
Zenyk likes to shuffle the bags. In one shuffle operation, he picks two adjacent bags and swaps their positions, but only if the total number of potatoes in those two bags does not exceed k. Zenyk can perform as many shuffle operations as he wants.
Marichka and Zenyk wondered how many different bag arrangements Zenyk can reach. Two arrangements are considered different if some position holds bags with different numbers of potatoes. Count the arrangements Zenyk can achieve.
Input
The first line contains two integers n and k (, ).
The second line contains n integers a_i ().
Output
Print one integer, the number of different arrangements modulo .