結果

問題 No.885 アマリクエリ
ユーザー tentententen
提出日時 2021-12-06 16:16:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 952 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 4,500 ms
コンパイル使用メモリ 75,396 KB
実行使用メモリ 66,732 KB
最終ジャッジ日時 2023-09-21 15:34:36
合計ジャッジ時間 11,193 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 952 ms
66,176 KB
testcase_01 AC 706 ms
66,492 KB
testcase_02 AC 516 ms
65,068 KB
testcase_03 AC 423 ms
64,096 KB
testcase_04 AC 435 ms
63,996 KB
testcase_05 AC 298 ms
59,612 KB
testcase_06 AC 267 ms
56,412 KB
testcase_07 AC 226 ms
57,980 KB
testcase_08 AC 248 ms
55,508 KB
testcase_09 AC 746 ms
66,732 KB
testcase_10 AC 46 ms
49,500 KB
testcase_11 AC 46 ms
49,744 KB
testcase_12 AC 46 ms
49,596 KB
testcase_13 AC 90 ms
52,048 KB
testcase_14 AC 101 ms
51,904 KB
testcase_15 AC 88 ms
52,748 KB
testcase_16 AC 76 ms
51,576 KB
testcase_17 AC 82 ms
51,668 KB
testcase_18 AC 81 ms
51,596 KB
testcase_19 AC 62 ms
51,512 KB
testcase_20 AC 61 ms
51,536 KB
testcase_21 AC 69 ms
51,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        long total = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            total += x;
            queue.add(-x);
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            while (queue.peek() <= -x) {
                int y = -queue.poll();
                total -= y;
                y %= x;
                total += y;
                queue.add(-y);
            }
            sb.append(total).append("\n");
        }
        System.out.print(sb);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0