Hermit Crabs
Time limit1sMemory limit128 MB
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 has an integer size . Because the crab grows, increases by every time unit, so at time its size is .
- Each shell has an integer size , which never changes.
- For a given constant , crab can live in shell at time if its size at that time satisfies . (A shell that is too large cannot be sealed at the entrance; a shell that is too small does not fit.)
- At time , crab lives in shell (the input guarantees the sizes fit).
- The instant a crab becomes too large for its current shell, that is, the instant its size exceeds , 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 at exactly the same instant another crab is looking for a shell, that other crab may move into shell .
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 .
Input
The first line contains the number of data sets. Then follow data sets, each of the following form.
The first line of a data set contains four integers , , , : is the number of hermit crabs and the number of shells, with ; is the constant from the description; and is the length of the observation period.
The next lines each contain one integer , the initial size of crab (all are distinct). The following lines each contain one integer , the size of shell (all are distinct). The input guarantees for , so shell initially fits crab .
Output
For each data set, first print a line Data Set x:, where is the data set number (starting from ). Then print, one per line and in increasing order, the indices of all crabs that are still alive at time . Follow each data set with one blank line.