Created
November 16, 2018 12:21
-
-
Save fpdjsns/fd7ad20bc1fb0b6d05568b4c5997d9c7 to your computer and use it in GitHub Desktop.
[codeground] 버스타기 : https://www.codeground.org/practice/practiceProblemViewNew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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