Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- int maski[n];
- for(int i = 0; i < n; i++) {
- cin >> maski[i];
- }
- sort(maski, maski + n);
- int m;
- cin >> m;
- int zenski[m];
- for(int i = 0; i < m; i++) {
- cin >> zenski[i];
- }
- sort(zenski, zenski + m);
- int R, k;
- cin >> R >> k;
- int res = 0;
- for(int i = 0; i + k - 1 < m; i++) {
- int najgolem = zenski[i] + R;
- int najmal = zenski[i + k - 1] - R;
- int L = 0, R = n;
- while(L < R) {
- int mid = L + (R - L) / 2;
- if(najmal <= maski[mid]) {
- R = mid;
- }
- else {
- L = mid + 1;
- }
- }
- if(L < n and maski[L] < najmal) {
- L++;
- }
- int id2 = L;
- L = 0, R = n;
- while(L < R) {
- int mid = L + (R - L) / 2;
- if(najgolem >= maski[mid]) {
- L = mid + 1;
- }
- else {
- R = mid;
- }
- }
- if(L < n and maski[L] <= najgolem) {
- L++;
- }
- res = max(res, L - id2);
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement