結果

問題 No.885 アマリクエリ
ユーザー Mr.Spock
提出日時 2020-11-10 19:56:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 802 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 207,312 KB
最終ジャッジ日時 2025-01-15 21:59:45
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  ll sum = 0;
  map<ll, ll>m;
  vector<ll>v(n);
  for (ll i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    m[v[i]]++;
  }
  ll q;
  cin >> q;
  set<ll>s;
  for (auto k : m) {
    s.insert(k.first);
  }
  ll ans = 0;
  for (ll i = 0; i < q; i++) {
    ll x;
    cin >> x;
    while (*s.rbegin() >= x) {
      ll aftermod = (*s.rbegin() % x);
      ll cnt = m[*s.rbegin()];
      sum -= (*s.rbegin() - aftermod) * cnt;
      m[*s.rbegin()] = 0;
      s.erase(*s.rbegin());
      s.insert(aftermod);
      m[aftermod] += cnt;
    }
    cout << sum << endl;
  }
}
0