CF886E.Maximum Element
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for finding maximum element in an array of n positive integers was too slow. Desperate, Petya decided to use a somewhat unexpected optimization using parameter k , so now his function contains the following code:
<br></br>int fast_max(int n, int a[]) { <br></br> int ans = 0;<br></br> int offset = 0;<br></br> for (int i = 0; i < n; ++i)<br></br> if (ans < a[i]) {<br></br> ans = a[i];<br></br> offset = 0;<br></br> } else {<br></br> offset = offset + 1;<br></br> if (offset == k)<br></br> return ans;<br></br> }<br></br> return ans;<br></br>}<br></br>
That way the function iteratively checks array elements, storing the intermediate maximum, and if after k consecutive iterations that maximum has not changed, it is returned as the answer.
Now Petya is interested in fault rate of his function. He asked you to find the number of permutations of integers from 1 to n such that the return value of his function on those permutations is not equal to n . Since this number could be very big, output the answer modulo 109+7 .
输入格式
The only line contains two integers n and k ( 1<=n,k<=106 ), separated by a space — the length of the permutations and the parameter k .
输出格式
Output the answer to the problem modulo 109+7 .
输入输出样例
输入#1
5 2
输出#1
22
输入#2
5 3
输出#2
6
输入#3
6 3
输出#3
84
说明/提示
Permutations from second example:
[4,1,2,3,5] , [4,1,3,2,5] , [4,2,1,3,5] , [4,2,3,1,5] , [4,3,1,2,5] , [4,3,2,1,5] .