結果

問題 No.999 てん vs. ほむ
ユーザー htensaihtensai
提出日時 2020-03-25 10:49:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 841 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 71,296 KB
実行使用メモリ 64,892 KB
最終ジャッジ日時 2023-08-30 09:29:06
合計ジャッジ時間 15,454 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,668 KB
testcase_01 AC 123 ms
55,552 KB
testcase_02 AC 124 ms
55,820 KB
testcase_03 AC 131 ms
55,900 KB
testcase_04 AC 140 ms
55,520 KB
testcase_05 AC 147 ms
57,920 KB
testcase_06 AC 137 ms
57,636 KB
testcase_07 AC 140 ms
55,516 KB
testcase_08 AC 232 ms
59,352 KB
testcase_09 AC 790 ms
64,584 KB
testcase_10 AC 494 ms
60,444 KB
testcase_11 AC 420 ms
61,032 KB
testcase_12 AC 538 ms
60,700 KB
testcase_13 AC 805 ms
63,132 KB
testcase_14 AC 814 ms
64,388 KB
testcase_15 AC 793 ms
64,656 KB
testcase_16 AC 806 ms
64,740 KB
testcase_17 AC 712 ms
64,532 KB
testcase_18 AC 665 ms
64,852 KB
testcase_19 AC 704 ms
64,516 KB
testcase_20 AC 701 ms
64,460 KB
testcase_21 AC 790 ms
64,892 KB
testcase_22 AC 841 ms
64,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n + 2];
        long[] left = new long[n + 2];
        for (int i = 1; i <= n; i++) {
            arr[i] = sc.nextInt() - sc.nextInt();
            left[i] = left[i - 1] + arr[i];
        }
        long[] right = new long[n + 2];
        for (int i = n; i >= 1; i--) {
            right[i] = right[i + 1] - arr[i];
        }
        long max = Long.MIN_VALUE;
        for (int i = 0; i <= n; i++) {
            max = Math.max(max, left[i] + right[i + 1]);
        }
        System.out.println(max);
    }
}
0