結果

問題 No.885 アマリクエリ
コンテスト
ユーザー k0hn0yutal2l5
提出日時 2019-09-13 23:48:09
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 830 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 539 ms
コンパイル使用メモリ 89,556 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-25 18:24:09
合計ジャッジ時間 3,206 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long ll;

typedef pair<ll, int> P;

ll X[100000];

priority_queue<P> que;

int main()
{
    ll N;
    ll sum = 0;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        ll A;
        cin >> A;
        sum += A;
        que.push(P(A, i));
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        int X;
        cin >> X;
        while (true)
        {
            P top = que.top();
            if (top.first >= X)
            {
                que.pop();
                sum -= top.first;
                sum += top.first % X;
                que.push(P(top.first % X, top.second));
            }
            else
            {
                break;
            }
        }
        cout << sum << endl;
    }
}
0