Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created November 16, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/fd7ad20bc1fb0b6d05568b4c5997d9c7 to your computer and use it in GitHub Desktop.
Save fpdjsns/fd7ad20bc1fb0b6d05568b4c5997d9c7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int Answer;
int main(int argc, char** argv)
{
int T, test_case;
cin >> T;
for (test_case = 0; test_case < T; test_case++)
{
int N, K;
cin >> N >> K;
vector<int> arr(N);
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
sort(arr.begin(), arr.end());
Answer = 0;
int L = 0;
for (int R = 0; R < N; R++) {
// except I can go with arr[R]
while (L < R && arr[R] - arr[L] > K) {
L++;
}
Answer = max(Answer, R - L + 1);
}
cout << "Case #" << test_case + 1 << endl;
cout << Answer << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment