結果
問題 |
No.885 アマリクエリ
|
ユーザー |
![]() |
提出日時 | 2021-05-22 21:14:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,154 ms / 2,000 ms |
コード長 | 525 bytes |
コンパイル時間 | 351 ms |
コンパイル使用メモリ | 48,768 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-10-10 20:41:00 |
合計ジャッジ時間 | 5,586 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <cstdio> #include <set> using namespace std; int main() { int N; scanf("%d", &N); long long sum = 0; multiset<int> ms; for (int i = 0; i < N; i++) { int x; scanf("%d", &x); ms.insert(x); sum += x; } int Q; scanf("%d", &Q); for (int i = 0; i < Q; i++) { int m; scanf("%d", &m); multiset<int>::iterator it; while ((it = ms.lower_bound(m)) != ms.end()) { int val = *it; sum += (val % m) - val; ms.erase(it); ms.insert(val % m); } printf("%lld\n", sum); } return 0; }