結果
問題 | No.885 アマリクエリ |
ユーザー |
![]() |
提出日時 | 2019-09-13 22:01:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 875 ms / 2,000 ms |
コード長 | 550 bytes |
コンパイル時間 | 1,453 ms |
コンパイル使用メモリ | 169,816 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-07-04 04:15:36 |
合計ジャッジ時間 | 6,654 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define modulo 1000000007#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)#define Inf 100000000int main(){int N;cin>>N;multiset<int> S;long long ans = 0;for(int i=0;i<N;i++){int a;cin>>a;ans += (long long)a;S.insert(a);}int Q;cin>>Q;for(int i=0;i<Q;i++){int X;cin>>X;auto it = S.lower_bound(X);while(it!=S.end()){int A = *it;ans -= A;S.insert(A%X);ans += A%X;it = S.erase(it);}cout<<ans<<endl;}return 0;}