using System;
namespace SE310
{
class Program
{
static void Main(string[] args)
{
//*** DO NOT CHANGE THE CODE IN THE MAIN METHOD *******
/*To test your code:
1- run the VPL (Ctr+F11)
2- input the integers of the array on the console like 7 1 2 3 4
3- input the k like 2
the output will be> 1,7,4
*/
/*
To evaluate your code (if evaluate is enabled):
1- Click on the evaluate button (Shift+F11)
2- the output of the evaluate will be shown on the right panel.
*/
try
{
string input1 = Console.ReadLine();
string input2 = Console.ReadLine();
string[] Astr = input1.Split(' ');
int[] A = null;
if (Astr.Length == 1)
{
int x;
if (int.TryParse(Astr[0], out x))
A = new int[] { x };
}
else
{
A = Array.ConvertAll(Astr, s => int.Parse(s));
}
int k = int.Parse(input2);
Console.WriteLine(FindAll(A, k));
}
catch (Exception e)
{
Console.WriteLine("wrong");
}
}
public static string FindAll(int[] a, int k)
{
if (a == null || a.Length == 0)
return "-1,-1,-1";
int min = a[0];
int max = a[0];
int[] sortedUnique = new int[a.Length];
Array.Copy(a, sortedUnique, a.Length);
for (int i = 1; i < a.Length; i++)
{
if (a[i] < min)
min = a[i];
if (a[i] > max)
max = a[i];
}
for (int i = 0; i < sortedUnique.Length - 1; i++)
{
for (int j = 0; j < sortedUnique.Length - 1 - i; j++)
{
if (sortedUnique[j] < sortedUnique[j + 1])
{
int temp = sortedUnique[j];
sortedUnique[j] = sortedUnique[j + 1];
sortedUnique[j + 1] = temp;
}
}
}
int newSize = 0;
for (int i = 0; i < sortedUnique.Length; i++)
{
if (i == 0 || sortedUnique[i] != sortedUnique[i - 1])
{
sortedUnique[newSize] = sortedUnique[i];
newSize++;
}
}
Array.Resize(ref sortedUnique, newSize);
int kth = -1;
if (k <= sortedUnique.Length)
kth = sortedUnique[k - 1];
return $"{min},{max},{kth}";
}
}
}