public static void Main()
Console.WriteLine(MaxProfit(new int[]{2,4,1}));
public static int MaxProfit(int[] prices) {
if(prices.Length == 1) return 0;
int buyingPrice = prices[0];
for(int i = 1;i < prices.Length; i++)
if(prices[i] < buyingPrice)
FinalProfit += (sellingPrice - buyingPrice);
if(sellingPrice < prices[i])
sellingPrice = prices[i];
if(i == prices.Length-1) FinalProfit += (sellingPrice - buyingPrice);
FinalProfit += (sellingPrice - buyingPrice);