結果

問題 No.885 アマリクエリ
ユーザー tekihei2317
提出日時 2019-09-14 10:10:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 176,148 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-07-05 17:13:45
合計ジャッジ時間 4,710 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{   
    int N; cin>>N;
    map<int,int> M;
    int sum=0;
    for(int i=0;i<N;i++){
        int a; cin>>a;
        M[a]++;
        sum+=a;
    }

    int Q; cin>>Q;
    while(Q--){
        int x; cin>>x;
        while(M.rbegin()->first>=x){
            int num=M.rbegin()->first;
            int cnt=M.rbegin()->second;
            sum-=(num-num%x)*cnt;
            M.erase(num);
            M[num%x]+=cnt;
        }
        cout<<sum<<endl;
    }
    return 0;
}
0