Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation
      • 19
        BFS

  • Best matcher

    You’ve decided to implement the simplest version of a dating app. For that, you’ve decided to collect the heights of boys as and the heights of girls . You’ve decided to match as many pairs as possible (one person can only be matched once). And you think that couples will be okay if the girl’s height is not shorter than the boy’s by x and the girl is not taller than the boy by more than y.
    You’d like to match as many pairs as possible.

    Input

    The first line of the input contains a 4 integers n, m (1 ≤ n, m ≤ ), x, and y (0 ≤ x, y ≤ ) - the number of boys, the number of girls, and the bounds for acceptable heights. The next line contains n integers representing the heights of the boys (1 ≤ ). The line after that contains m integers representing the heights of the girls (1 ≤ ).

    Output

    The program should print the maximum number of pairs matched.

    Examples

    Input
    Output
    6 2 0 0 1 2 3 4 5 6 6 7
    1
    3 3 1 1 4 5 6 3 4 7
    3
     

    Constraints

    Time limit: 1 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue