結果

問題 No.999 てん vs. ほむ
ユーザー bluemeganebluemegane
提出日時 2020-09-11 11:31:34
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 61,140 KB
実行使用メモリ 46,408 KB
最終ジャッジ日時 2023-08-26 16:57:55
合計ジャッジ時間 5,783 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,640 KB
testcase_01 AC 53 ms
22,680 KB
testcase_02 AC 53 ms
22,712 KB
testcase_03 AC 53 ms
20,724 KB
testcase_04 AC 55 ms
22,672 KB
testcase_05 AC 60 ms
20,736 KB
testcase_06 AC 53 ms
20,632 KB
testcase_07 AC 60 ms
18,668 KB
testcase_08 AC 64 ms
23,136 KB
testcase_09 AC 125 ms
39,500 KB
testcase_10 AC 80 ms
25,592 KB
testcase_11 AC 72 ms
22,700 KB
testcase_12 AC 87 ms
27,444 KB
testcase_13 AC 138 ms
42,324 KB
testcase_14 AC 140 ms
44,384 KB
testcase_15 AC 138 ms
46,384 KB
testcase_16 AC 138 ms
46,408 KB
testcase_17 AC 116 ms
40,920 KB
testcase_18 AC 114 ms
38,684 KB
testcase_19 AC 115 ms
38,772 KB
testcase_20 AC 114 ms
36,772 KB
testcase_21 AC 129 ms
40,300 KB
testcase_22 AC 128 ms
42,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = new int[n];
        var b = new int[n];
        var bsum = 0L;
        var sum = 0L;
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(line[i * 2]);
            b[i] = int.Parse(line[i * 2 + 1]);
            bsum += b[i];
            sum += a[i] + b[i];
        }
        getAns(n, a, b, bsum, sum);
    }
    static void getAns(int n, int[] a, int[] b, long bsum, long sum)
    {
        var ans = 2 * bsum - sum;
        var asum = 0L;
        for (int i = 0; i < n; i++)
        {
            asum += a[i];
            bsum -= b[i];
            ans = Max(ans, 2 * asum + 2 * bsum - sum);
        }
        Console.WriteLine(ans);
    }
}
0