Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
- template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
- template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
- template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using vl = vector<ll>;
- using vi = vector<int>;
- int main(int argc, char **argv)
- {
- int t;
- cin >> t;
- while (t--) {
- int n, k;
- cin >> n >> k;
- vi a(n), b(n);
- for (auto &x : a)
- cin >> x;
- for (auto &x : b)
- cin >> x;
- sort(a.begin(), a.end());
- vi one_pass(n);
- vi max_op(n);
- for (int i = 0; i < n; ++i)
- one_pass[i] = upper_bound(a.begin(), a.end(), a[i]) - lower_bound(a.begin(), a.end(), a[i] - k);
- max_op[0] = one_pass[0];
- for (int i = 1; i < n; ++i)
- max_op[i] = max(max_op[i - 1], one_pass[i]);
- int ans = 0;
- for (int i = 0; i < n; ++i) {
- int op_id = lower_bound(a.begin(), a.end(), a[i] - k) - a.begin() - 1;
- int best = (op_id >= 0 ? max_op[op_id] : 0) + one_pass[i];
- ans = max(ans, best);
- }
- cout << ans << endl;
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement