#C12980. Descending Array Search Algorithms

    ID: 42467 Type: Default 1000ms 256MiB

Descending Array Search Algorithms

Descending Array Search Algorithms

This problem requires you to implement and compare two search algorithms on a descendingly sorted array of integers. The first algorithm is a binary search modified for descending order, and the second is a simple linear search. Both functions should return the index of the target if it is found; otherwise, they should return -1.

For the binary search, remember that the array is sorted in descending order. Hence, the traditional binary search condition is reversed. In mathematical terms, if the middle element is denoted as \(a_{mid}\) and the target is \(T\), the binary search decision is based on:

[ \text{if } a_{mid} < T \text{ then search the left part, otherwise search the right part.} ]

Your task is to implement both search functions and output their results for the given input.

inputFormat

The input is given via standard input (stdin) and has the following format:

  1. An integer n representing the number of elements in the array.
  2. n space-separated integers representing the array. The array is guaranteed to be sorted in descending order.
  3. An integer representing the target value to search for.

outputFormat

Output two lines to standard output (stdout):

  1. The first line should contain the index returned by the binary search function.
  2. The second line should contain the index returned by the linear search function.

If the target is not found, output -1 for that search.

## sample
5
15 10 5 3 1
10
1

1

</p>