結果
問題 | No.885 アマリクエリ |
ユーザー |
![]() |
提出日時 | 2019-09-13 22:25:37 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 975 ms / 2,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 2,288 ms |
コンパイル使用メモリ | 87,924 KB |
実行使用メモリ | 75,212 KB |
最終ジャッジ日時 | 2024-07-04 09:58:43 |
合計ジャッジ時間 | 11,735 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
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(); } }