Beispiel #1
0
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            N  = ss.Next(int.Parse);
            C  = ss.Next(long.Parse);
            XV = ss.Next(long.Parse, 2, N).Select(a => new XVPair(a[0], a[1])).ToArray();

            var tr1 = GetMaxValuesOfDist(true, 1);
            var tr2 = GetMaxValuesOfDist(true, 2);
            var tl1 = GetMaxValuesOfDist(false, 1);
            var tl2 = GetMaxValuesOfDist(false, 2);

            var max = 0L;

            for (var i = 0; i <= N; i++)
            {
                max = Math.Max(max, tr1[i] + tl2[N - i]);
                max = Math.Max(max, tr2[i] + tl1[N - i]);
            }

            sw.WriteLine(max);
            //---------------------------------
        }