# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
513900 | heroescharge | 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 <iostream>
#include <fstream>
using namespace std;
int N, D;
int f(int arr[]) {
int p1loc = 0;
int p1val = 0;
int p2loc = 0;
int vals[N];
while (p2loc < N) {
while (arr[p1loc] <= arr[p2loc] + D && p1loc < N) {
p1loc++;
p1val++;
}
vals[p2loc] = p1val;
p2loc++;
p1val--;
}
int prod = 1;
int M = 1000000009;
for (int i = 0; i < N; i++) {
prod = (prod * (vals[i] % M)) % M;
}
return prod;
}
int main() {
cin >> N >> D;
int arr[N];
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
sort(arr, arr + N);
cout << f(arr);
}