CSES - Putka Open 2020 – 5/5 - Results
Submission details
Task:Järjestys
Sender:mango_lassi
Submission time:2020-11-28 00:20:28 +0200
Language:C++ (C++11)
Status:READY
Result:26
Feedback
groupverdictscore
#1ACCEPTED26
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#20.01 s2details
#30.01 s2details

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = (int)1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;
	for (int ti = 0; ti < t; ++ti) {
		int n, x;
		cin >> n >> x;

		vector<int> vals(n);
		for (int& v : vals) cin >> v;
		sort(vals.begin(), vals.end());
		
		int j = 0, res = 1;
		for (int i = 0; i < n; ++i) {
			while(j < n && vals[i] >= vals[j] - x) ++j;
			res = (res * (j-i)) % MOD;
		}
		cout << res << '\n';
	}
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
100
5 20
65 49 97 55 9
6 33
42 32 10 92 60 37
...

correct output
6
192
4
72
288
...

user output
6
192
4
72
288
...
Truncated

Test 2

Group: 2

Verdict:

input
100
85 980
570 804 393 119 973 743 345 46...

correct output
753889928
541098438
241592657
827522722
403761060
...

user output
-974471376
-955033423
-762136282
-606953337
-62014664
...
Truncated

Test 3

Group: 2

Verdict:

input
100
100 1
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
988185646
196898158
546822979
56844088
346866189
...

user output
988185646
13537933
-317700793
831703234
-833172318
...
Truncated