using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int ieCount = int.Parse(Reader.ReadLine()); List tempList = new List(); int okashiTotal = 0; for(int i=0; i{ if(a.Okashi + a.Sikii < b.Okashi + b.Sikii) { return -1; } else if(a.Okashi + a.Sikii > b.Okashi + b.Sikii) { return 1; } else if(a.Sikii < b.Sikii) { return -1; } else if(a.Sikii > b.Sikii) { return 1; } return 0; }); this.IeList = tempList.ToArray(); int ans = this.GetAns(0,0); Console.WriteLine(ans); } private Dictionary> dic = new Dictionary>(); private int GetAns(int idx, int hasOkashi) { if(!this.dic.ContainsKey(idx)) { this.dic.Add(idx, new Dictionary()); } if(this.dic[idx].ContainsKey(hasOkashi)) { return this.dic[idx][hasOkashi]; } int ans = 0; if(idx >= this.IeList.Length) { return ans; } if(idx == this.IeList.Length - 1) { if(IeList[idx].Sikii > hasOkashi) { ans = IeList[idx].Okashi; } else { ans = 0; } } else { for(int i=idx; iint.Parse(a)).ToArray(); this.Index = idx; this.Okashi = inpt[0]; this.Sikii = inpt[1]; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 1 3 100 2 "; 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(); } }