結果
| 問題 |
No.885 アマリクエリ
|
| ユーザー |
|
| 提出日時 | 2019-09-14 18:03:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,373 bytes |
| コンパイル時間 | 1,636 ms |
| コンパイル使用メモリ | 177,308 KB |
| 実行使用メモリ | 9,856 KB |
| 最終ジャッジ日時 | 2024-07-06 06:27:08 |
| 合計ジャッジ時間 | 4,799 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 13 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
int main() {
int n;
cin >> n;
map<ll, ll> m;
ll t = 0;
ll a;
REP(i, n) {
cin >> a;
t += a;
m[a]++;
}
int q;
cin >> q;
ll x;
REP(i, q) {
ll s = t;
cin >> x;
for (auto itr = m.rbegin(); itr != m.rend(); itr++) {
if (itr->second == 0) continue;
if (itr->first >= x) {
ll y = itr->first - itr->first % x;
if (y == 0) {
s -= itr->first * itr->second;
m[0] += itr->second;
m.erase(itr->first);
} else {
s -= (itr->first - itr->first % x) * itr->second;
m[itr->first % x] += itr->second;
m.erase(itr->first);
}
} else {
break;
}
}
cout << s << endl;
t = s;
}
}