# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546539 | MilosMilutinovic | A Huge Tower (CEOI10_tower) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define N 100000
#define MD 1000000007
int n, d, aa[N], bb[N];
long long dp[N];
void sort(int l, int r) {
int i, cc0, cc1;
if (l >= r)
return;
int m = (l + r) / 2;
sort(l, m);
sort(m + 1, r);
cc0 = l, cc1 = m + 1;
for (i = l; i <= r; i++)
if (cc0 > m || (cc1 <= r && aa[cc0] > aa[cc1]))
bb[i] = aa[cc1++];
else
bb[i] = aa[cc0++];
for (i = l; i <= r; i++)
aa[i] = bb[i];
}
int main() {
int i, j;
scanf("%d%d", &n, &d);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
sort(0, n - 1);
for (i = 0, j = 0; i < n; i++) {
while (a[j] < a[i] - d)
j++;
dp[i] = (i == 0 ? 1LL : dp[i - 1]) * (i - j + 1), dp[i] = (dp[i] % MD);
}
printf("%lld\n", dp[n - 1]);
return 0;
}