結果

問題 No.885 アマリクエリ
ユーザー erbowl
提出日時 2020-03-20 16:35:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 382 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 171,980 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-14 09:13:55
合計ジャッジ時間 6,112 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll n;
    std::cin >> n;
    priority_queue<ll> pq;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        ll tmp;
        std::cin >> tmp;
        sum += tmp;
        pq.push(tmp);
    }
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll tmp;
        std::cin >> tmp;
        while(pq.top()>=tmp){
            auto now = pq.top();pq.pop();
            sum -= now-now%tmp;
            pq.push(now%tmp);
        }
        std::cout << sum << std::endl;
    }
    
    
}
0