結果
| 問題 | No.885 アマリクエリ |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-08-31 14:38:45 |
| 言語 | Java (openjdk 26.0.2.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1,141 ms / 2,000 ms |
| + 526µs | |
| コード長 | 1,189 bytes |
| 記録 | |
| コンパイル時間 | 1,677 ms |
| コンパイル使用メモリ | 97,720 KB |
| 実行使用メモリ | 90,148 KB |
| 最終ジャッジ日時 | 2026-09-23 19:17:37 |
| 合計ジャッジ時間 | 13,176 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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);
}
}
tenten