結果

問題 No.999 てん vs. ほむ
ユーザー ks2mks2m
提出日時 2020-02-28 21:31:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 2,546 ms
コンパイル使用メモリ 77,336 KB
実行使用メモリ 62,996 KB
最終ジャッジ日時 2024-04-21 17:55:41
合計ジャッジ時間 9,368 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
37,044 KB
testcase_01 AC 62 ms
37,160 KB
testcase_02 AC 61 ms
37,052 KB
testcase_03 AC 64 ms
37,040 KB
testcase_04 AC 61 ms
36,968 KB
testcase_05 AC 65 ms
36,792 KB
testcase_06 AC 63 ms
36,856 KB
testcase_07 AC 63 ms
37,084 KB
testcase_08 AC 106 ms
39,360 KB
testcase_09 AC 333 ms
57,232 KB
testcase_10 AC 216 ms
45,056 KB
testcase_11 AC 183 ms
45,680 KB
testcase_12 AC 370 ms
49,364 KB
testcase_13 AC 371 ms
62,224 KB
testcase_14 AC 375 ms
62,996 KB
testcase_15 AC 377 ms
62,128 KB
testcase_16 AC 377 ms
62,180 KB
testcase_17 AC 324 ms
57,476 KB
testcase_18 AC 338 ms
57,068 KB
testcase_19 AC 344 ms
58,128 KB
testcase_20 AC 328 ms
56,956 KB
testcase_21 AC 338 ms
58,188 KB
testcase_22 AC 341 ms
57,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		long[] l = new long[n + 1];
		long[] r = new long[n + 1];
		for (int i = 0; i < n; i++) {
			l[i + 1] = Integer.parseInt(sa[i * 2]);
			r[i + 1] = Integer.parseInt(sa[i * 2 + 1]);
		}
		br.close();

		for (int i = 1; i <= n; i++) {
			l[i] += l[i - 1];
			r[i] += r[i - 1];
		}
		long total = l[n] + r[n];

		long ans = Long.MIN_VALUE;
		for (int i = 0; i <= n; i++) {
			long val1 = l[i] + r[n] - r[i];
			long val2 = total - val1;
			val1 -= val2;
			ans = Math.max(ans, val1);
		}
		System.out.println(ans);
	}
}
0