using System.Collections.Generic;
public static void Main()
List<int> chests = new List<int> {7,8,9};
Console.Write("Maximum treasure that can be collected is "+ GetResult(chests, t));
public static int GetResult(List<int> chests, int t)
for (int i = 0; i < chests.Count && t > 0; i++)
return result += chests[i];
return Math.Max(i, chests[i+1]);