Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static final long MOD = 1000000007;
- public void solve () throws Exception {
- int n = nextInt();
- int t = nextInt();
- long c [][] = new long [n + 1][n + 1];
- for (int i = 0; i <= n; i++) {
- c[i][0] = c[i][i] = 1;
- for (int j = 1; j < i; j++) {
- c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
- }
- }
- int a [] = new int [n];
- int count [] = new int [5001];
- for (int i = 0; i < n; i++) {
- a [i] = nextInt();
- count [a[i]]++;
- }
- int p = a[nextInt() - 1];
- int pos = nextInt();
- int pleft = pos - 1;
- int pright = t - pos;
- int countLeft = 0;
- int countRight = 0;
- for (int i = 0; i < p; i++) {
- countLeft += count [i];
- }
- for (int i = p + 1; i <= 5000; i++) {
- countRight += count [i];
- }
- long answer = 0;
- for (int left = 0; left <= count [p] - 1; left++) {
- for (int right = 0; right + left <= count [p] - 1 && left <= pleft && right <= pright; right++) {
- long cur = c[count[p] - 1][left + right];
- long la = (c[countLeft][pleft - left]) % MOD;
- cur = (cur * la) % MOD;
- long ra = (c[countRight][pright - right]) % MOD;
- cur = (cur * ra) % MOD;
- answer = (answer + cur) % MOD;
- }
- }
- out.println(answer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement