結果

問題 No.885 アマリクエリ
ユーザー pekempey
提出日時 2019-09-13 21:40:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 171,560 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-04 04:03:49
合計ジャッジ時間 4,062 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  priority_queue<int> q;
  ll ans = 0;
  rep(i, N) {
    int A; cin >> A;
    q.push(A);
    ans += A;
  }
  int Q; cin >> Q;
  while (Q--) {
    int X; cin >> X;
    while (q.top() >= X) {
      int x = q.top(); q.pop();
      ans -= x;
      x %= X;
      ans += x;
      q.push(x);
    }
    cout << ans << '\n';
  }
}
0