#C2375. Finding a Contiguous Segment with Given Sum

    ID: 45684 Type: Default 1000ms 256MiB

Finding a Contiguous Segment with Given Sum

Finding a Contiguous Segment with Given Sum

You are given a sequence of books with a certain number of pages. Your task is to find a contiguous segment of these books whose total number of pages is exactly p. Formally, given an array \(a_1, a_2, \dots, a_n\) of positive integers and a target \(p\), find indices \(l\) and \(r\) (with \(1 \le l \le r \le n\)) such that

[ \sum_{i=l}^{r} a_i = p ]

If such a segment exists, output the indices \(l\) and \(r\) (1-indexed); otherwise, output -1.

The input is read from standard input (stdin) and the output is written to standard output (stdout).

inputFormat

The first line contains two integers \(n\) and \(p\), where \(n\) is the number of books and \(p\) is the target sum.

The second line contains \(n\) integers representing the number of pages in each book, separated by spaces.

outputFormat

If a contiguous segment exists whose sum equals \(p\), output two integers representing the starting and ending indices (1-indexed) separated by a space.

If no such segment exists, output -1.

## sample
5 12
1 2 3 7 5
2 4