Visit origins

3.7

3 votes
Problem

You are given a sequence of moves as a string s of size n consisting of only two characters L and R where L denotes that you have to move left by 1 unit and R denotes that you have to move right by 1 unit from your current position.

Consider a straight track as X-axis with an origin O and every point on the track is separated by 1 unit. You are required to determine the starting point on the track from where you have started executing the provided sequence so that you can visit the origin O that denotes the maximum number of times. If there are many such points, then print the left most of them.

Note: Starting point is also included in the visited count

Input format

  • First line: integer n denoting the size of the string
  • Next lines: String s of size n consisting of only L and R as described in the problem statement

Output format

Two space separated integer c and p that denote the maximum number of times you visited origin and the point from where you started respectively. If there are many such points, then print the left most of them.

Constraints

1n2×105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first sample input:
We have s = "LLRLR", if we start from point 1. The visited points in sequence are 1 (start), 0, -1, 0, -1, 0.
So, we will visit origin 3 times, which is maximum. Hence, the answer will be 3 (max number of times) and 1 (starting point).

Editor Image

?