結果

問題 No.885 アマリクエリ
ユーザー htensaihtensai
提出日時 2019-12-10 17:02:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,477 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 2,665 ms
コンパイル使用メモリ 73,092 KB
実行使用メモリ 77,924 KB
最終ジャッジ日時 2023-09-06 07:12:05
合計ジャッジ時間 16,328 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,477 ms
77,924 KB
testcase_01 AC 1,240 ms
73,120 KB
testcase_02 AC 950 ms
68,964 KB
testcase_03 AC 936 ms
69,476 KB
testcase_04 AC 908 ms
67,036 KB
testcase_05 AC 701 ms
66,868 KB
testcase_06 AC 628 ms
67,296 KB
testcase_07 AC 562 ms
63,684 KB
testcase_08 AC 564 ms
61,356 KB
testcase_09 AC 1,299 ms
74,780 KB
testcase_10 AC 119 ms
56,028 KB
testcase_11 AC 119 ms
56,092 KB
testcase_12 AC 120 ms
56,724 KB
testcase_13 AC 205 ms
59,072 KB
testcase_14 AC 199 ms
58,588 KB
testcase_15 AC 204 ms
59,320 KB
testcase_16 AC 204 ms
60,800 KB
testcase_17 AC 205 ms
58,424 KB
testcase_18 AC 208 ms
58,624 KB
testcase_19 AC 173 ms
55,896 KB
testcase_20 AC 174 ms
56,212 KB
testcase_21 AC 193 ms
56,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long total = 0;
        PriorityQueue<Integer> queue = new PriorityQueue<Integer>(new Comparator<Integer>() {
            public int compare(Integer i1, Integer i2) {
                return i2.intValue() - i1.intValue();
            }
        });
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            total += x;
            queue.add(x);
        }
        int q = sc.nextInt();
        int min = Integer.MAX_VALUE;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            if (x < min) {
                min = x;
                while(queue.peek() >= x) {
                    int y = queue.poll();
                    total -= y / x * x;
                    queue.add(y % x);
                }
            }
            sb.append(total).append("\n");
        }
        System.out.print(sb);
    }
}
0