Ashu and his array

0

0 votes
Easy-Medium
Problem

Ashu is playing with an array of n element. He picks every possible combination of two elements and makes a new sequence of (n×(n1))/2 elements i.e two numbers are distinct only if the two elements that are picked for multiplication are at different positions. For example with array 1,2,3 the possible are (1,2) , (1,3) , (2,3) i.e 3 numbers in the newly formed sequence. Now he is caught playing (it was the study time) and is given a value x and he has to write the xth number in the newly formed sequence after **sorting it**. Can you help him.
Input
First line contains a number n as input denoting total numbers in the original sequence. Next line contains n space separated integers that denote the elements of the array. Next line contains an integer x.Output
In the output you have to write the value of the element at position x in the newly formed array. Remember there can be duplicates in the array.
Constraints
1n105
1A[i]105
1x((n×(n1))/2)

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

The given array is 1,2,1,1. When we pick pairs of elements and generate the new array it will look like - 2,1,1,2,2,1. After you sort it , it will look like 1,1,1,2,2,2. Now the element at the 4th position of this array is 2 so the output is 2.

Editor Image

?