public static void Main()
int[] dailyPrices = {2, 10, 6, 4, 5, 3, 1, 3, 9, 11};
int time = GetBestProfitIdeal(dailyPrices);
Console.WriteLine("Max profit was at hour {0} and the cost was: {1}",time, dailyPrices[time]);
public static int GetBestProfitIdeal(int[] dailyPrices){
for (int i=0; i < dailyPrices.Length - 1; i++)
for (int j=i+1; j < dailyPrices.Length; j++)
if (price < dailyPrices[j] && profit < (dailyPrices[j] - price)){
profit = (dailyPrices[j] - price);