using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int [] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int numCount = inpt[0]; int kujiCount = inpt[1]; int maxTotal = 0; int maxIdx = 0; for(int i=0; i numList = new List(); inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); numList.Add(inpt[0]); numList.Add(inpt[1]); for(int j=2; j ret = null; if(j - k > 1) { int[] tmp = numList.Skip(k + 1).Where(a=>a > numBig || a < numSmall).ToArray(); if(tmp.Length > 0) { ret = tmp.Max(); max = Math.Max(max, Math.Max(ret.Value, numBig)); } } if(k > 0) { int[] tmp = numList.Take(k).Where(a=> (inpt[j] > inpt[k] && a > inpt[k]) || (inpt[j] < inpt[k] && a < inpt[k])).ToArray(); if(tmp.Length > 0) { ret = tmp.Max(); max = Math.Max(max, Math.Max(ret.Value, numBig)); } } if(j < inpt.Length - 1) { int[] tmp = inpt.Skip(j).Where(a=>(inpt[j] > inpt[k] && inpt[j] > a) || (inpt[j] < inpt[k] && inpt[j] < a)).ToArray(); if(tmp.Length > 0) { ret = tmp.Max(); max = Math.Max(max, Math.Max(ret.Value, numBig)); } } total += max; } numList.Add(inpt[j]); } if(maxTotal < total) { maxTotal = total; maxIdx = i; } } if(maxIdx < 0) { maxIdx = 0; } Console.WriteLine(maxIdx); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 5 3 2 1 3 4 5 3 2 1 5 4 5 2 4 1 3 "; 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(); } }