#P9952. Maximize Minimum Distance with Two New Cows

    ID: 23096 Type: Default 1000ms 256MiB

Maximize Minimum Distance with Two New Cows

Maximize Minimum Distance with Two New Cows

A new disease, COWVID-19, is spreading among cows worldwide. Farmer John is taking all possible precautions to protect his herd.

The cow barn is a long building with N stalls arranged in a row (\(2 \le N \le 10^5\)). Some stalls already contain cows while others are empty. Aware of the importance of "social distancing", Farmer John wants the value \(D\) to be as large as possible, where \(D\) is defined as the distance between the two closest occupied stalls (i.e. if stalls 3 and 8 are the closest occupied stalls, then \(D=5\)).

Now, two new cows have arrived. Farmer John must decide in which two empty stalls to place these new cows in order to keep \(D\) as large as possible. He cannot move any of the cows already present; he can only assign the new cows to empty stalls.

Your task is to help him choose two stall positions so that after placing the two new cows, the minimum distance between any two adjacent occupied stalls (when sorted in increasing order) is maximized. If there are multiple optimal solutions, you may print any one of them.

Note: The distance between stalls is measured by the absolute difference of their indices.

inputFormat

The first line contains a single integer \(N\) representing the total number of stalls.

The second line contains a string of length \(N\) consisting of characters '0' and '1'. The \(i\)th character is '1' if stall \(i\) is occupied by a cow, and '0' if it is empty. It is guaranteed that there are at least two empty stalls.

outputFormat

Output two integers separated by a space, representing the positions (1-indexed) of the stalls where the two new cows should be placed. The chosen stalls must be empty. If there are multiple optimal solutions, output any one.

sample

5
10101
2 4

</p>