using System; using System.Collections.Generic; using System.Linq; //No.370 道路の掃除 class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("3 5"); WillReturn.Add("1"); WillReturn.Add("2"); WillReturn.Add("3"); WillReturn.Add("4"); WillReturn.Add("5"); //3 } else if (InputPattern == "Input2") { WillReturn.Add("2 4"); WillReturn.Add("-5"); WillReturn.Add("-1"); WillReturn.Add("2"); WillReturn.Add("5"); //4 } else if (InputPattern == "Input3") { WillReturn.Add("2 5"); WillReturn.Add("-3"); WillReturn.Add("-1"); WillReturn.Add("0"); WillReturn.Add("2"); WillReturn.Add("4"); //1 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int[] wkArr = { }; Action SplitAct = pStr => wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray(); SplitAct(InputList[0]); int N = wkArr[0]; int[] DArr = InputList.Skip(1).Select(X => int.Parse(X)).ToArray(); Array.Sort(DArr); int UB = DArr.GetUpperBound(0); int Answer = int.MaxValue; for (int I = 0; I <= UB; I++) { int MinInd = I; int MaxInd = I + N - 1; if (MaxInd > UB) break; int MinD = DArr[MinInd]; int MaxD = DArr[MaxInd]; int KyoriSum = 0; if (MinD > 0) { //両方とも正の場合 KyoriSum = MaxD; } else if (MaxD < 0) { //両方とも負の場合 KyoriSum = Math.Abs(MinD); } else { //符号が異なる場合 int wkSum1 = Math.Abs(MinD) * 2 + MaxD; int wkSum2 = Math.Abs(MinD) + MaxD * 2; KyoriSum = Math.Min(wkSum1, wkSum2); } if (Answer > KyoriSum) Answer = KyoriSum; } Console.WriteLine(Answer); } }