結果

問題 No.885 アマリクエリ
ユーザー merom686merom686
提出日時 2019-09-13 22:31:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 85,892 KB
実行使用メモリ 8,168 KB
最終ジャッジ日時 2023-09-17 14:49:54
合計ジャッジ時間 2,851 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,380 KB
testcase_01 AC 170 ms
8,168 KB
testcase_02 AC 71 ms
7,988 KB
testcase_03 AC 29 ms
4,380 KB
testcase_04 AC 30 ms
4,380 KB
testcase_05 AC 24 ms
4,376 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 37 ms
7,992 KB
testcase_08 AC 18 ms
4,376 KB
testcase_09 AC 187 ms
8,008 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    ll s = 0;
    map<int, int, greater<>> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        s += a;
        mp[a]++;
    }

    int q;
    cin >> q;

    for (int h = 0; h < q; h++) {
        int x;
        cin >> x;

        while (1) {
            auto it = mp.begin();
            if (it->first < x) break;
            int a = it->first;
            int c = it->second;
            mp.erase(it);
            int b = a % x;
            mp[b] += c;
            s -= (ll)(a - b) * c;
        }
        cout << s << '\n';
    }

    return 0;
}
0