Attacking Pairs
InterviewTime limit2sMemory limit1024 MB
Given n strengths, find any pair of creatures within index distance k whose strength difference lies in [l, r], or report -1 -1 if none exists.
- Level
Medium6 of 10
- Topics
- Sliding window, Binary search, Sorting
- Solved
- No attempts yet
Statement
Underwater world is in hard times, and a war has broken out. Aquaman gathered his army of different creatures, lined them up, and numbered them from to . The -th creature has strength .
Aquaman learned the following fighting technique from his mother: pairs of creatures are sent into battle, strike a precise blow on the enemy army, and then immediately return to their places in the line. Not every pair can be sent, though. Only pairs of creatures that satisfy
are suitable.
To begin, to see whether his army has any chance of winning, Aquaman wants to find any pair of creatures that can be sent into battle. Help him.
Input
The first line contains four integers , , , : the number of creatures in Aquaman's army, and the limits on and respectively (, , ).
The second line contains integers , the strengths of the creatures ().
Output
If a pair of creatures that can be sent exists, print the two indices and on a single line. If several pairs are possible, print any of them. If no such pair exists, print and on a single line.
Hint
In the first example, Aquaman has only one pair that can be sent into battle: and , since and .
In the second example, a pair can be sent only if the strengths are equal, but the array has no two equal elements.