using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray(); int countInBox = (int)inpt[0]; long mustEat = inpt[1]; this.IceList = Reader.ReadLine().Select(a=>int.Parse(a.ToString())).ToArray(); long ans = 0; if(this.IceList.Sum(a=>a) > this.IceList.Length) { ans = this.GetAns2(mustEat, 0); } else { ans = this.GetAns(0, 0, mustEat, 0); } Console.WriteLine(ans); } int[] IceList; private long GetAns(long buyCount, long getCount, long musEat, long charge) { if(charge >= musEat - getCount) { return buyCount; } long subBuy = buyCount; long subGet = getCount; long subCharge = charge; if(dic.ContainsKey(charge)) { long buyTemp = buyCount - this.dic[charge].BuyCount; long getTemp = getCount - this.dic[charge].GetCount; long remain = musEat - getCount; if(remain > getTemp) { long mul = remain / getTemp; subBuy = buyTemp * mul; subGet = getTemp * mul; } } else { dic.Add(charge, new HakoState(buyCount, getCount)); } for(int i=0; i 0) { subCharge--; } else { subBuy++; } subGet++; subCharge+=this.IceList[i]; } if(subGet < musEat) { subBuy = this.GetAns(subBuy, subGet, musEat, subCharge); } return subBuy; } private long GetAns2(long remain, long charge) { if(remain <= charge) { return 0; } if(charge >=IceList.Length) { return 0; } long ans = 0; long subRemain = remain; long subCharge = charge; for(int i=0; i 0) { subCharge--; subRemain--; } else { ans++; subRemain--; } subCharge+=IceList[i]; } ans += this.GetAns2(subRemain, subCharge); return ans; } private Dictionary dic = new Dictionary(); public class HakoState { public long BuyCount; public long GetCount; public HakoState(long buy, long gt) { this.BuyCount = buy; this.GetCount = gt; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 5 01 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }