using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int itemCount = int.Parse(Reader.ReadLine()); this.BlockList = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int maxYama = this.GetPiramidMax(this.BlockList.Sum()); int ans = this.BlockList.Sum(); for (int i = maxYama; i >= 1; i--) { ans = Math.Min(ans, GetMoveCount(i)); } Console.WriteLine(ans); } private int[] BlockList; private int GetMoveCount(int num) { List yama = new List(); for (int i = 1; i <= num; i++) { yama.Add(i); } for (int i = num - 1; i >= 1;i--) { yama.Add(i); } for (int i = 0; i < BlockList.Length; i++) { yama.Add(0); } int ans = 0; for (int i = 0; i < yama.Count; i++) { if(i>=BlockList.Length) { break; } if(BlockList[i]>yama[i]) { ans += BlockList[i] - yama[i]; } } return ans; } private int GetPiramidMax(int num) { for (int i = num; i >= 1; i--) { int cnt = NeedCountBlock(i); if(cnt <= num) { return i; } } return 1; } private int NeedCountBlock(int maxColumnHeight) { if(maxColumnHeight == 1) { return 1; } int cnt = maxColumnHeight * (maxColumnHeight + 1) / 2; cnt += maxColumnHeight * (maxColumnHeight - 1) / 2; return cnt; } public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 9 1 1 1 1 1 1 1 1 1 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }