Ribbon (Easy)
InterviewTime limit1sMemory limit1024 MB
Given N ribbons with positions, lengths, and colors, find two ribbons of different colors that can be tied together, or report NO.
- Level
Easy2 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
You are given ribbons tied to points on a number line. The -th ribbon is tied to the point and has length . Its color is , which is one of R, Y, or B, meaning red, yellow, and blue.
You want to tie a knot between two ribbons. The ribbons are not elastic, so you cannot stretch them, but you can bend them. That means you can tie a knot between the -th and -th ribbons if . Assume the ribbons are lines with no area, and ignore the length of the knot. A knot is called beautiful when the two ribbons have different colors, that is, .
Write a program that finds two ribbon numbers that can be tied into a beautiful knot.
Input
The first line contains an integer .
The second line contains integers .
The third line contains integers .
The fourth line contains characters .
Output
If a valid pair exists, print YES on the first line. Otherwise, print NO.
If a valid pair exists, print the numbers of two ribbons that can be tied into a beautiful knot on the second line.
If several answers exist, you may print any of them.
Constraints
- is one of
R,Y,B.