#C11411. Find First and Last Positions of a Target in a Sorted List
Find First and Last Positions of a Target in a Sorted List
Find First and Last Positions of a Target in a Sorted List
You are given an integer \( M \) representing the number of scores, a list of \( M \) integers representing the scores, and an integer \( target \). Your task is to sort the list and then find the first and last positions (0-indexed) at which the \( target \) appears. If the \( target \) does not exist in the list, output \( -1 \) for both positions.
Formally, given a sorted list \( A \) (after sorting) and a target \( x \), find the smallest index \( i \) and largest index \( j \) such that \( A[i] = A[j] = x \). If \( x \) is not present in \( A \), then output \( i = j = -1 \).
Note: If the list is empty, output \( -1 -1 \).
inputFormat
The input is given via standard input with the following format:
M s1 s2 s3 ... sM target
Here, \( M \) is the number of scores. If \( M = 0 \), the second line (score list) will be empty. The third line contains the target integer.
outputFormat
Output a single line containing two integers separated by a space representing the first and last positions of the target in the sorted score list. If the target does not exist in the list, output "-1 -1".
## sample8
1 3 3 5 5 5 7 8
5
3 5