結果

問題 No.885 アマリクエリ
ユーザー ks2m
提出日時 2019-09-13 22:21:58
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 3,037 ms
コンパイル使用メモリ 88,568 KB
実行使用メモリ 64,316 KB
最終ジャッジ日時 2024-07-04 09:56:52
合計ジャッジ時間 11,565 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 13
権限があれば一括ダウンロードができます

ソースコード

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();

		int 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