結果

問題 No.885 アマリクエリ
ユーザー roundplusroundplus
提出日時 2019-09-23 17:51:43
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 504 ms / 2,000 ms
コード長 2,203 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 106,252 KB
実行使用メモリ 4,604 KB
最終ジャッジ日時 2023-08-20 12:57:30
合計ジャッジ時間 6,051 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 504 ms
4,588 KB
testcase_01 AC 417 ms
4,604 KB
testcase_02 AC 350 ms
4,524 KB
testcase_03 AC 351 ms
4,604 KB
testcase_04 AC 351 ms
4,544 KB
testcase_05 AC 316 ms
4,556 KB
testcase_06 AC 285 ms
4,604 KB
testcase_07 AC 44 ms
4,576 KB
testcase_08 AC 299 ms
4,380 KB
testcase_09 AC 414 ms
4,592 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 5 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N; cin >> N;
    vector<ll>A(N);
    priority_queue<int>pq;
    lli sum=0LL;

    rep(i,N){
        cin >> A[i];
        pq.push(A[i]);
        sum+=A[i];
    }

    int Q; cin >> Q;
    for(int i=0; i<Q; i++){
        int X; cin >> X;
        while (!pq.empty() && pq.top()>=X){
            ll a=pq.top();
            pq.pop();
            sum-=a;
            sum+=a%X;
            pq.push(a%X);
        }
        cout << sum << flush << endl;
    }

    return 0;
}
0