結果
問題 | No.885 アマリクエリ |
ユーザー |
![]() |
提出日時 | 2020-08-31 14:38:45 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,740 ms / 2,000 ms |
コード長 | 1,189 bytes |
コンパイル時間 | 2,260 ms |
コンパイル使用メモリ | 79,508 KB |
実行使用メモリ | 84,264 KB |
最終ジャッジ日時 | 2024-11-15 23:07:20 |
合計ジャッジ時間 | 17,722 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long sum = 0; TreeMap<Integer, Integer> remain = new TreeMap<>(); for (int i = 0; i < n; i++) { int x = - sc.nextInt(); if (remain.containsKey(x)) { remain.put(x, remain.get(x) + 1); } else { remain.put(x, 1); } sum -= x; } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int y = sc.nextInt(); while (- remain.firstKey() >= y) { Map.Entry<Integer, Integer> entry = remain.pollFirstEntry(); int x = - entry.getKey(); sum -= (long)x * entry.getValue(); int mod = x % y; if (remain.containsKey(-mod)) { remain.put(-mod, remain.get(-mod) + entry.getValue()); } else { remain.put(-mod, entry.getValue()); } sum += (long)mod * entry.getValue(); } sb.append(sum).append("\n"); } System.out.print(sb); } }