結果
| 問題 |
No.885 アマリクエリ
|
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2019-06-25 21:23:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 2,000 ms |
| コード長 | 747 bytes |
| コンパイル時間 | 780 ms |
| コンパイル使用メモリ | 64,344 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-23 08:40:29 |
| 合計ジャッジ時間 | 3,239 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <queue>
#include <iostream>
#ifdef _WIN32
#define getchar_fast _getchar_nolock
#else
#define getchar_fast getchar_unlocked
#endif
int ri() {
int r = 0, c, s = 0;
for (;;) {c=getchar_fast(); if (c == '-') { s = 1; break; } if (c <= '9' && c >= '0') { r = c - '0'; break; } }
for (;;) {c=getchar_fast(); if (c < '0' || c > '9') break; r = r * 10 + c - '0'; }
if (s) r = -r;
return r;
}
int main() {
int n = ri();
std::priority_queue<int> que;
long long sum = 0;
for (int i = 0; i < n; i++) {
int a = ri();
sum += a;
que.push(a);
}
int q = ri();
for (int i = 0; i < q; i++) {
int x = ri();
int t;
while ((t = que.top()) >= x) sum -= t - t % x, que.pop(), que.push(t % x);
printf("%lld\n", sum);
}
return 0;
}
QCFium