結果
| 問題 |
No.885 アマリクエリ
|
| ユーザー |
|
| 提出日時 | 2020-08-04 19:47:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 231 ms / 2,000 ms |
| コード長 | 748 bytes |
| コンパイル時間 | 757 ms |
| コンパイル使用メモリ | 76,004 KB |
| 最終ジャッジ日時 | 2025-01-12 14:23:36 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <queue>
template <class T>
using MaxHeap = std::priority_queue<T>;
using lint = long long;
void solve() {
int n;
std::cin >> n;
lint sum = 0;
MaxHeap<lint> heap;
while (n--) {
lint x;
std::cin >> x;
sum += x;
heap.push(x);
}
int q;
std::cin >> q;
while (q--) {
lint x;
std::cin >> x;
while (heap.top() >= x) {
auto y = heap.top();
heap.pop();
sum -= y;
y %= x;
heap.push(y);
sum += y;
}
std::cout << sum << "\n";
}
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}