結果

問題 No.2008 Super Worker
ユーザー CuriousFairy315
提出日時 2022-07-15 21:31:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,559 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 79,364 KB
実行使用メモリ 65,916 KB
最終ジャッジ日時 2024-06-27 16:59:31
合計ジャッジ時間 25,830 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #


import static java.lang.System.err;
import static java.lang.System.out;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
	public static void main(String[] args) {
		new Main();
		out.flush();
		err.flush();
	}
	
	public static class Pair implements Comparable<Pair>{
		int A, B;
		Pair(int A, int B) {
			this.A = A;
			this.B = B;
		}
		@Override
		public int compareTo(Pair o) {
			return Long.compare(A + (long)B * o.A, o.A + (long)o.B * A);
		}
	}

	public Main() {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int N = sc.nextInt();
			int[] A = new int[N], B = new int[N];
			for (int i = 0;i < N;++ i) A[i] = sc.nextInt();
			for (int i = 0;i < N;++ i) B[i] = sc.nextInt();
			Pair[] p = new Pair[N];
			for (int i = 0;i < N;++ i) p[i] = new Pair(A[i], B[i]);
			Arrays.sort(p, Comparator.reverseOrder());
			final int MOD = 1_000_000_007;
			long level = 1;
			long ans = 0;
			for (Pair i : p) {
				ans = (ans + level * i.A) % MOD;
				level = level * i.B % MOD;
			}
			out.println(ans);
		}
	}
}
0