Submission #2552977


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;


#if DEBUG
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif

namespace competitive_programming
{
    public class Program
    {
        static void Main(string[] args)
        {
#if DEBUG
            var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open));
#else
            var scanner = new IO.StreamScanner(Console.OpenStandardInput());
#endif

            var n = scanner.Integer();
            var c = scanner.Long();
            var x = new List<long>();
            var v = new List<long>();
            for (int i = 0; i < n; i++)
            {
                x.Add(scanner.Long());
                v.Add(scanner.Long());
            }
            IO.Printer.Out.WriteLine(GetAns(n, c, x, v));
            IO.Printer.Out.Flush();
        }

        public static long GetAns(int n, long c, List<long> x, List<long> v)
        {
            var accum = 0L;
            var maxScores_r = new long[n + 1];
            for (int i = 0; i < x.Count(); i++)
            {
                accum += v[i];
                maxScores_r[i + 1] = Math.Max(maxScores_r[i], accum - x[i]);
            }

            accum = 0L;
            var maxScores_l = new long[n + 1];
            for (int i = 0; i < x.Count(); i++)
            {
                accum += v[n - 1 - i];
                maxScores_l[i + 1] = Math.Max(maxScores_l[i], accum - (c - x[n - i - 1]));
            }

            var ret = 0L;
            for (int i = 0; i < x.Count(); i++)
            {
                ret = Math.Max(ret, maxScores_r[i + 1]);
                ret = Math.Max(ret, maxScores_r[i + 1] + maxScores_l[n - i - 1] - x[i]);
                ret = Math.Max(ret, maxScores_l[i + 1]);
                ret = Math.Max(ret, maxScores_l[i + 1] + maxScores_r[n - i - 1] - (c - x[n - i - 1]));
            }

            return ret;
        }
    }


#if DEBUG
    [TestClass]
    public class Test
    {
    }
#endif

    namespace IO
    {
        using System.IO;
        using System.Text;
        using System.Globalization;

        public class Printer : StreamWriter
        {
            static Printer()
            {
                Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
            }

            public static Printer Out { get; set; }

            public override IFormatProvider FormatProvider
            {
                get { return CultureInfo.InvariantCulture; }
            }

            public Printer(Stream stream)
                : base(stream, new UTF8Encoding(false, true))
            {
            }

            public Printer(Stream stream, Encoding encoding)
                : base(stream, encoding)
            {
            }

            public void Write<T>(string format, T[] source)
            {
                base.Write(format, source.OfType<object>().ToArray());
            }

            public void WriteLine<T>(string format, T[] source)
            {
                base.WriteLine(format, source.OfType<object>().ToArray());
            }
        }

        public class StreamScanner
        {
            public StreamScanner(Stream stream)
            {
                str = stream;
            }

            public readonly Stream str;
            private readonly byte[] buf = new byte[1024];
            private int len, ptr;
            public bool isEof;

            public bool IsEndOfStream
            {
                get { return isEof; }
            }

            private byte read()
            {
                if (isEof) return 0;
                if (ptr < len) return buf[ptr++];
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++];
                isEof = true;
                return 0;
            }

            public char Char()
            {
                byte b;
                do b = read(); while ((b < 33 || 126 < b) && !isEof);
                return (char)b;
            }

            public string Scan()
            {
                var sb = new StringBuilder();
                for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                    sb.Append(b);
                return sb.ToString();
            }

            public string ScanLine()
            {
                var sb = new StringBuilder();
                for (var b = Char(); b != '\n'; b = (char)read())
                    if (b == 0) break;
                    else if (b != '\r') sb.Append(b);
                return sb.ToString();
            }

            public long Long()
            {
                if (isEof) return long.MinValue;
                long ret = 0;
                byte b;
                var ng = false;
                do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b));
                if (b == 0) return long.MinValue;
                if (b == '-')
                {
                    ng = true;
                    b = read();
                }
                for (; ; b = read())
                {
                    if (b < '0' || '9' < b)
                        return ng ? -ret : ret;
                    ret = ret * 10 + b - '0';
                }
            }

            public int Integer()
            {
                return (isEof) ? int.MinValue : (int)Long();
            }

            public double Double()
            {
                var s = Scan();
                return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN;
            }

            static T[] enumerate<T>(int n, Func<T> f)
            {
                var a = new T[n];
                for (int i = 0; i < n; ++i) a[i] = f();
                return a;
            }

            public char[] Char(int n)
            {
                return enumerate(n, Char);
            }

            public string[] Scan(int n)
            {
                return enumerate(n, Scan);
            }

            public double[] Double(int n)
            {
                return enumerate(n, Double);
            }

            public int[] Integer(int n)
            {
                return enumerate(n, Integer);
            }

            public long[] Long(int n)
            {
                return enumerate(n, Long);
            }
        }
    }
}

Submission Info

Submission Time
Task D - Static Sushi
User yambe2002
Language C# (Mono 4.6.2.0)
Score 500
Code Size 6638 Byte
Status AC
Exec Time 48 ms
Memory 16224 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 300 / 300 200 / 200
Status
AC × 4
AC × 29
AC × 50
Set Name Test Cases
Sample a01, a02, a03, a04
Subtask1 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29
Subtask2 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50
Case Name Status Exec Time Memory
a01 AC 29 ms 11220 KB
a02 AC 22 ms 11220 KB
a03 AC 22 ms 9172 KB
a04 AC 22 ms 9172 KB
b05 AC 22 ms 11220 KB
b06 AC 22 ms 11220 KB
b07 AC 23 ms 11220 KB
b08 AC 22 ms 9172 KB
b09 AC 22 ms 9172 KB
b10 AC 22 ms 9172 KB
b11 AC 22 ms 9172 KB
b12 AC 22 ms 9172 KB
b13 AC 22 ms 11220 KB
b14 AC 22 ms 9172 KB
b15 AC 22 ms 11220 KB
b16 AC 22 ms 9172 KB
b17 AC 22 ms 9172 KB
b18 AC 23 ms 13268 KB
b19 AC 22 ms 9172 KB
b20 AC 23 ms 11220 KB
b21 AC 23 ms 11220 KB
b22 AC 22 ms 11220 KB
b23 AC 23 ms 11220 KB
b24 AC 22 ms 11220 KB
b25 AC 23 ms 11220 KB
b26 AC 22 ms 11220 KB
b27 AC 22 ms 9172 KB
b28 AC 22 ms 11220 KB
b29 AC 22 ms 9172 KB
c30 AC 37 ms 16224 KB
c31 AC 42 ms 14176 KB
c32 AC 48 ms 14176 KB
c33 AC 48 ms 14176 KB
c34 AC 48 ms 14176 KB
c35 AC 37 ms 14176 KB
c36 AC 48 ms 16224 KB
c37 AC 46 ms 14176 KB
c38 AC 47 ms 16224 KB
c39 AC 47 ms 14176 KB
c40 AC 47 ms 14176 KB
c41 AC 46 ms 16224 KB
c42 AC 46 ms 16224 KB
c43 AC 24 ms 9696 KB
c44 AC 47 ms 16224 KB
c45 AC 22 ms 9252 KB
c46 AC 46 ms 16224 KB
c47 AC 22 ms 9172 KB
c48 AC 47 ms 14176 KB
c49 AC 46 ms 16224 KB
c50 AC 47 ms 14176 KB