結果

問題 No.885 アマリクエリ
ユーザー ks2mks2m
提出日時 2019-09-13 22:25:37
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,073 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 76,484 KB
最終ジャッジ日時 2023-09-17 14:44:46
合計ジャッジ時間 11,562 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,073 ms
68,292 KB
testcase_01 AC 846 ms
75,672 KB
testcase_02 AC 608 ms
71,912 KB
testcase_03 AC 472 ms
71,704 KB
testcase_04 AC 571 ms
75,152 KB
testcase_05 AC 381 ms
67,764 KB
testcase_06 AC 341 ms
66,308 KB
testcase_07 AC 263 ms
64,328 KB
testcase_08 AC 307 ms
63,328 KB
testcase_09 AC 821 ms
76,484 KB
testcase_10 AC 54 ms
50,632 KB
testcase_11 AC 54 ms
51,196 KB
testcase_12 AC 55 ms
50,248 KB
testcase_13 AC 100 ms
53,208 KB
testcase_14 AC 102 ms
53,172 KB
testcase_15 AC 101 ms
53,016 KB
testcase_16 AC 91 ms
53,248 KB
testcase_17 AC 96 ms
52,960 KB
testcase_18 AC 83 ms
52,796 KB
testcase_19 AC 68 ms
52,404 KB
testcase_20 AC 87 ms
52,924 KB
testcase_21 AC 71 ms
52,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;

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(" ");
		PriorityQueue<Integer> que = new PriorityQueue<>((o1, o2) -> o2 - o1);
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
			que.add(a[i]);
		}
		int q = Integer.parseInt(br.readLine());
		sa = br.readLine().split(" ");
		int[] x = new int[q];
		for (int i = 0; i < q; i++) {
			x[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i];
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			while (que.peek() >= x[i]) {
				int cur = que.poll();
				int next = cur % x[i];
				que.add(next);
				sum -= cur - next;
			}
			pw.println(sum);
		}
		pw.flush();
	}
}
0