結果

問題 No.2284 Assembly
ユーザー ks2mks2m
提出日時 2023-04-28 22:22:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 3,594 ms
コンパイル使用メモリ 71,376 KB
実行使用メモリ 58,552 KB
最終ジャッジ日時 2023-08-11 07:16:28
合計ジャッジ時間 9,895 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,292 KB
testcase_01 AC 43 ms
49,140 KB
testcase_02 AC 45 ms
49,680 KB
testcase_03 AC 48 ms
49,340 KB
testcase_04 AC 45 ms
49,156 KB
testcase_05 AC 44 ms
49,520 KB
testcase_06 AC 44 ms
49,664 KB
testcase_07 AC 42 ms
49,328 KB
testcase_08 AC 379 ms
57,652 KB
testcase_09 AC 381 ms
57,640 KB
testcase_10 AC 368 ms
57,088 KB
testcase_11 AC 382 ms
57,920 KB
testcase_12 AC 379 ms
57,124 KB
testcase_13 AC 358 ms
58,552 KB
testcase_14 AC 379 ms
57,548 KB
testcase_15 AC 373 ms
57,368 KB
testcase_16 AC 370 ms
57,300 KB
testcase_17 AC 383 ms
55,520 KB
testcase_18 AC 412 ms
57,244 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());
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]);
			b[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		long[] a2 = new long[n + 1];
		long[] b2 = new long[n + 1];
		for (int i = n - 1; i >= 0; i--) {
			a2[i] = a2[i + 1] + a[i];
			b2[i] = b2[i + 1] + b[i];
		}

		long ans = 0;
		for (int i = 0; i < n; i++) {
			long v1 = a[i] * b2[i + 1];
			long v2 = b[i] * a2[i + 1];
			ans += Math.max(v1, v2);
		}
		System.out.println(ans);
	}
}
0