Hermit Crabs

Time limit1sMemory limit128 MB

Summary
Simulate hermit crabs that outgrow shells over time and fight for larger unoccupied shells, then list survivors at time T.
Level

Medium7 of 10

Topics
Simulation, Sorting, Greedy, Implementation
Solved
No attempts yet

Problem

On many beaches you can see hermit crabs, which are quite interesting creatures. They are relatives of crabs, but have a soft belly, so to protect themselves they must live inside the empty shells of sea snails. What you actually see is a snail shell scurrying briskly along the beach; when you get close, the crab pulls itself inside and the shell looks like an ordinary shell, except that a big claw seals the entrance. Like most animals, hermit crabs grow over time, so sooner or later they must move to a bigger shell. A crab that cannot find a suitable shell is usually eaten very quickly, and when shells are scarce the crabs even fight one another for them. Here we determine which crabs survive as they outgrow their shells.

To keep things simple we assume the following.

  • Each hermit crab ii has an integer size ci≥0c_i \ge 0. Because the crab grows, cic_i increases by 11 every time unit, so at time tt its size is ci+tc_i + t.
  • Each shell jj has an integer size sj≥0s_j \ge 0, which never changes.
  • For a given constant DD, crab ii can live in shell jj at time tt if its size at that time satisfies sj−D≤ci+t≤sjs_j - D \le c_i + t \le s_j. (A shell that is too large cannot be sealed at the entrance; a shell that is too small does not fit.)
  • At time 00, crab ii lives in shell ii (the input guarantees the sizes fit).
  • The instant a crab becomes too large for its current shell, that is, the instant its size exceeds sjs_j, it leaves that shell and moves into the largest currently unoccupied shell it can fit into. If no such shell exists at that instant, a bird eats it.
  • If several crabs try to move into the same shell at exactly the same instant, they fight, and only the largest crab wanting that shell survives; the others are eaten.
  • If a crab leaves shell jj at exactly the same instant another crab is looking for a shell, that other crab may move into shell jj.

No two crabs ever have the same size, and no two shells ever have the same size, so every choice above is uniquely determined. Report which crabs are still alive at time TT.

Input

The first line contains the number KK of data sets. Then follow KK data sets, each of the following form.

The first line of a data set contains four integers nn, mm, DD, TT: nn is the number of hermit crabs and mm the number of shells, with 1≤n≤m≤10001 \le n \le m \le 1000; DD is the constant from the description; and TT is the length of the observation period.

The next nn lines each contain one integer cic_i, the initial size of crab ii (all cic_i are distinct). The following mm lines each contain one integer sjs_j, the size of shell jj (all sjs_j are distinct). The input guarantees si−D≤ci≤sis_i - D \le c_i \le s_i for i=1,…,ni = 1, \dots, n, so shell ii initially fits crab ii.

Output

For each data set, first print a line Data Set x:, where xx is the data set number (starting from 11). Then print, one per line and in increasing order, the indices of all crabs that are still alive at time TT. Follow each data set with one blank line.

Examples3

  1. Example 1

    Input
    2
    3 4 100 133
    300
    310
    120
    350
    360
    155
    450
    2 3 10 17
    13
    21
    16
    23
    32
    
    Expected output
    Data Set 1:
    2
    
    Data Set 2:
    
    
  2. Example 2

    Input
    1
    1 1 5 3
    10
    13
    
    Expected output
    Data Set 1:
    1
    
    
  3. Example 3

    Input
    1
    1 1 5 6
    10
    15
    
    Expected output
    Data Set 1: