結果
| 問題 | No.885 アマリクエリ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-13 23:07:22 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 161 ms / 2,000 ms |
| コード長 | 886 bytes |
| 記録 | |
| コンパイル時間 | 1,257 ms |
| コンパイル使用メモリ | 188,116 KB |
| 実行使用メモリ | 9,924 KB |
| 最終ジャッジ日時 | 2026-03-25 18:12:45 |
| 合計ジャッジ時間 | 3,152 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
multiset<ll> s;
ll sum = 0;
for (int i = 0; i < n; i++) {
ll a;
cin >> a;
s.insert(a);
sum += a;
}
int q;
cin >> q;
ll minx = 1e15;
for (int i = 0; i < q; i++) {
ll x;
cin >> x;
if (minx <= x) {
cout << sum << "\n";
continue;
}
minx = x;
auto beg = s.lower_bound(minx);
vector<ll> v;
for (auto it = beg; it != s.end(); ++it) {
v.push_back(*it);
sum -= v.back();
v.back() %= minx;
sum += v.back();
}
cout << sum << "\n";
s.erase(beg, s.end());
s.insert(v.begin(), v.end());
}
return 0;
}