Submission #534329


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Numerics;
using System.Globalization;

namespace Solver
{
    class Program
    {
        const int M = 1000000007;
        const double eps = 1e-9;
        static void Main()
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            var sc = new Scan();
            int n = sc.Int;
            var a = sc.LongArr;
            var b = sc.LongArr;
            long max = b[0] * n;
            long used = 0;
            long maxb = b[0];
            long sum = 0;
            for (int i = 0; i < n - 1; i++)
            {
                sum += a[i];
                if (sum < 0)
                {
                    if (maxb == 0)
                    {
                        sw.WriteLine(max);
                        sw.Flush();
                        return;
                    }
                    long t = (-sum - 1) / maxb + 1;
                    used += t;
                    if (used + i + 1 > n)
                    {
                        sw.WriteLine(max);
                        sw.Flush();
                        return;
                    }
                    sum += maxb * t;
                }
                maxb = Math.Max(maxb, b[i + 1]);
                max = Math.Max(max, sum + maxb * (n - i - 1 - used));
            }
            sw.WriteLine(Math.Max(max, a.Sum()));
            sw.Flush();
        }
    }
    class Scan
    {
        public int Int { get { return int.Parse(Console.ReadLine().Trim()); } }
        public long Long { get { return long.Parse(Console.ReadLine().Trim()); } }
        public string Str { get { return Console.ReadLine().Trim(); } }
        public int[] IntArr { get { return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); } }
        public int[] IntArrWithSep(char sep) { return Console.ReadLine().Trim().Split(sep).Select(int.Parse).ToArray(); }
        public long[] LongArr { get { return Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); } }
        public double[] DoubleArr { get { return Console.ReadLine().Split().Select(double.Parse).ToArray(); } }
        public string[] StrArr { get { return Console.ReadLine().Trim().Split(); } }
        public List<int> IntList { get { return Console.ReadLine().Trim().Split().Select(int.Parse).ToList(); } }
        public List<long> LongList { get { return Console.ReadLine().Trim().Split().Select(long.Parse).ToList(); } }
        public void Multi(out int a, out int b) { var arr = IntArr; a = arr[0]; b = arr[1]; }
        public void Multi(out int a, out int b, out int c) { var arr = IntArr; a = arr[0]; b = arr[1]; c = arr[2]; }
        public void Multi(out int a, out int b, out int c, out int d) { var arr = IntArr; a = arr[0]; b = arr[1]; c = arr[2]; d = arr[3]; }
        public void Multi(out int a, out string b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1]; }
        public void Multi(out int a, out int b, out string c) { var arr = StrArr; a = int.Parse(arr[0]); b = int.Parse(arr[1]); c = arr[2]; }
        public void Multi(out int a, out char b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1][0]; }
        public void Multi(out char a, out int b) { var arr = StrArr; a = arr[0][0]; b = int.Parse(arr[1]); }
        public void Multi(out long a, out long b) { var arr = LongArr; a = arr[0]; b = arr[1]; }
        public void Multi(out long a, out int b) { var arr = LongArr; a = arr[0]; b = (int)arr[1]; }
        public void Multi(out string a, out string b) { var arr = StrArr; a = arr[0]; b = arr[1]; }
    }
    class mymath
    {
        int M;
        const double eps = 1e-9;
        public mymath(int M) { this.M = M; }
        public long pow(long a, long b)
        {
            if (b == 0) return 1;
            if (b == 1) return a % M;

            long t = pow(a, b / 2);

            if ((b & 1) == 0) return t * t % M;
            else return t * t % M * a % M;
        }
        public long gcd(long a, long b)
        {
            while (b != 0)
            {
                var t = a % b;
                a = b;
                b = t;
            }
            return a;
        }
        public long lcm(int a, int b) { return (a * b) / gcd(a, b); }
    }
}

Submission Info

Submission Time
Task D - 高橋君の旅行
User riantkb
Language C# (Mono 3.2.1.0)
Score 200
Code Size 4449 Byte
Status AC
Exec Time 577 ms
Memory 39520 KB

Judge Result

Set Name Small All
Score / Max Score 3 / 3 197 / 197
Status
AC × 13
AC × 49
Set Name Test Cases
Small 00_small_sample_00.txt, 00_small_sample_01.txt, 00_small_sample_02.txt, 00_small_sample_03.txt, 10_small_01.txt, 10_small_02.txt, 10_small_03.txt, 10_small_04.txt, 10_small_05.txt, 10_small_06.txt, 90_small_teuchi_00.txt, 90_small_teuchi_01.txt, 90_small_teuchi_02.txt
All 00_small_sample_00.txt, 00_small_sample_01.txt, 00_small_sample_02.txt, 00_small_sample_03.txt, 10_small_01.txt, 10_small_02.txt, 10_small_03.txt, 10_small_04.txt, 10_small_05.txt, 10_small_06.txt, 20_large_01.txt, 20_large_02.txt, 20_large_03.txt, 20_large_04.txt, 20_large_05.txt, 20_large_06.txt, 20_large_07.txt, 20_large_08.txt, 20_large_09.txt, 20_large_10.txt, 20_large_11.txt, 20_large_12.txt, 20_large_13.txt, 20_large_14.txt, 20_large_15.txt, 20_large_16.txt, 20_large_17.txt, 20_large_18.txt, 20_large_19.txt, 20_large_20.txt, 20_large_21.txt, 20_large_22.txt, 20_large_23.txt, 20_large_24.txt, 20_large_25.txt, 20_large_26.txt, 20_large_27.txt, 20_large_28.txt, 20_large_29.txt, 20_large_30.txt, 30_run_through_01.txt, 70_maximum_01.txt, 80_hand_01.txt, 80_hand_02.txt, 80_hand_03.txt, 80_hand_04.txt, 90_small_teuchi_00.txt, 90_small_teuchi_01.txt, 90_small_teuchi_02.txt
Case Name Status Exec Time Memory
00_small_sample_00.txt AC 153 ms 10624 KB
00_small_sample_01.txt AC 156 ms 10596 KB
00_small_sample_02.txt AC 159 ms 10464 KB
00_small_sample_03.txt AC 153 ms 10592 KB
10_small_01.txt AC 161 ms 10612 KB
10_small_02.txt AC 154 ms 10472 KB
10_small_03.txt AC 156 ms 10448 KB
10_small_04.txt AC 156 ms 10584 KB
10_small_05.txt AC 155 ms 10492 KB
10_small_06.txt AC 157 ms 10616 KB
20_large_01.txt AC 510 ms 31956 KB
20_large_02.txt AC 547 ms 36988 KB
20_large_03.txt AC 550 ms 35900 KB
20_large_04.txt AC 509 ms 31848 KB
20_large_05.txt AC 544 ms 37856 KB
20_large_06.txt AC 538 ms 36100 KB
20_large_07.txt AC 506 ms 31940 KB
20_large_08.txt AC 540 ms 35788 KB
20_large_09.txt AC 544 ms 37212 KB
20_large_10.txt AC 504 ms 31572 KB
20_large_11.txt AC 535 ms 30848 KB
20_large_12.txt AC 536 ms 30848 KB
20_large_13.txt AC 497 ms 36160 KB
20_large_14.txt AC 523 ms 39520 KB
20_large_15.txt AC 518 ms 37828 KB
20_large_16.txt AC 520 ms 37168 KB
20_large_17.txt AC 516 ms 30844 KB
20_large_18.txt AC 525 ms 37768 KB
20_large_19.txt AC 508 ms 31444 KB
20_large_20.txt AC 535 ms 31576 KB
20_large_21.txt AC 535 ms 30960 KB
20_large_22.txt AC 505 ms 35796 KB
20_large_23.txt AC 524 ms 38676 KB
20_large_24.txt AC 524 ms 37972 KB
20_large_25.txt AC 510 ms 31180 KB
20_large_26.txt AC 536 ms 31216 KB
20_large_27.txt AC 534 ms 31068 KB
20_large_28.txt AC 505 ms 30572 KB
20_large_29.txt AC 532 ms 31828 KB
20_large_30.txt AC 535 ms 32484 KB
30_run_through_01.txt AC 526 ms 33124 KB
70_maximum_01.txt AC 577 ms 39040 KB
80_hand_01.txt AC 460 ms 30324 KB
80_hand_02.txt AC 461 ms 30292 KB
80_hand_03.txt AC 460 ms 30320 KB
80_hand_04.txt AC 461 ms 30288 KB
90_small_teuchi_00.txt AC 155 ms 10464 KB
90_small_teuchi_01.txt AC 155 ms 10580 KB
90_small_teuchi_02.txt AC 158 ms 10488 KB