Пример #1
0
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var A = ss.Next(long.Parse, N);

            var plan = new[] { 0L }.Concat(A).Concat(new[] { 0L }).ToArray();

            var cost = 0L;

            for (var i = 1; i < N + 2; i++)
            {
                cost += Math.Abs(plan[i - 1] - plan[i]);
            }

            for (var i = 1; i <= N; i++)
            {
                var via     = Math.Abs(plan[i - 1] - plan[i]) + Math.Abs(plan[i] - plan[i + 1]);
                var through = Math.Abs(plan[i - 1] - plan[i + 1]);
                sw.WriteLine(cost - via + through);
            }
            //---------------------------------
        }