help me find the error in my problem.
A very famous artist in certain circles, Ignat, painted one picture every day for N days. On the i day, Ignat painted a picture with bright colors ai.
Now Ignat wants to choose the most contrasting pair from N resulting pictures. Pair of paintings (i,j) drawn on days i and j, respectively, is called the most contrasting if the value (ai−aj) is maximal among all possible pairs.
Input data The first line contains an integer N — the number of days. The second line contains integers a1,a2,...,aN, where ai — the brightness of the picture drawn on the i day.
Output Print distinct integers i and j are the numbers of the days on which Ignat painted the most contrasting pair of pictures (i, j). The numbers i and j must lie between 1 and N. If there are several such pairs, print the pair with the maximum value of i−j. Note that the pair (i,j) differs from the pair (j,i). Input example: 6
1 2 1 3 1 3 Output: 6 1
Input example: 4
2 1 0 -1 Output: 1 4
My code:
int n = int.Parse(Console.ReadLine());
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int maxIndex = 0, minIndex = 0;
for (int i = 1; i < n; i++)
{
if (a[i] > a[maxIndex])
{
maxIndex = i;
}
if (a[i] < a[minIndex])
{
minIndex = i;
}
}
if (maxIndex < minIndex)
{
Console.WriteLine((maxIndex + 1) + " " + (minIndex + 1));
}
else
{
Console.WriteLine((minIndex + 1) + " " + (maxIndex + 1));
}
I always get 1 4, thank u very much