public void Proc() { int itemCount = int.Parse(Reader.ReadLine()); int[] timeArr = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int[] spdArr = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); for (int i = 0; i < itemCount; i++) { this.AreaList.Add(new Area(i, timeArr[i], spdArr[i])); } this.AreaList[0].EnterMaxSpeed = 0; this.AreaList.Last().LeaveMaxSpeed = 0; if (this.AreaList.Count > 1) { this.AreaList[0].LeaveMaxSpeed = Math.Min(this.AreaList[0].LeaveMaxSpeed, this.AreaList[1].EnterMaxSpeed); } Queue <Area> que = new Queue <Area>(); que.Enqueue(this.AreaList[0]); while (que.Count > 0) { Area current = que.Dequeue(); if (!current.IsModified) { continue; } current.IsModified = false; if (current.ID > 0) { Area prev = this.AreaList[current.ID - 1]; prev.LeaveMaxSpeed = Math.Min(prev.LeaveMaxSpeed, current.EnterMaxSpeed); que.Enqueue(prev); } if (current.ID < this.AreaList.Count - 1) { Area next = this.AreaList[current.ID + 1]; next.EnterMaxSpeed = Math.Min(next.EnterMaxSpeed, current.LeaveMaxSpeed); que.Enqueue(next); } } decimal ans = AreaList.Sum(a => a.GetLength()); Console.WriteLine(ans); }