結果

問題 No.2284 Assembly
ユーザー ks2mks2m
提出日時 2023-04-28 22:22:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 76,584 KB
実行使用メモリ 49,128 KB
最終ジャッジ日時 2024-04-28 23:53:54
合計ジャッジ時間 7,850 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
36,948 KB
testcase_01 AC 51 ms
36,680 KB
testcase_02 AC 52 ms
36,892 KB
testcase_03 AC 53 ms
36,488 KB
testcase_04 AC 53 ms
36,744 KB
testcase_05 AC 52 ms
36,888 KB
testcase_06 AC 52 ms
36,488 KB
testcase_07 AC 52 ms
36,860 KB
testcase_08 AC 401 ms
47,084 KB
testcase_09 AC 409 ms
48,808 KB
testcase_10 AC 398 ms
47,388 KB
testcase_11 AC 391 ms
47,488 KB
testcase_12 AC 395 ms
48,316 KB
testcase_13 AC 392 ms
47,212 KB
testcase_14 AC 405 ms
48,472 KB
testcase_15 AC 383 ms
48,708 KB
testcase_16 AC 385 ms
47,196 KB
testcase_17 AC 402 ms
48,872 KB
testcase_18 AC 411 ms
49,128 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