diff --git a/problem/P1296/P1296.cpp b/problem/P1296/P1296.cpp new file mode 100644 index 00000000..a86a2d53 --- /dev/null +++ b/problem/P1296/P1296.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main() { + int n, d, p[100005], ans = 0; + cin >> n >> d; + for (int i = 0; i < n; i++) { + cin >> p[i]; + } + sort(p, p + n); + for (int i = 0; i < n; i++) { + ans += (upper_bound(p + i, p + n, p[i] + d) - p) - i - 1; + } + cout << ans << endl; + return 0; +}