結果
| 問題 |
No.885 アマリクエリ
|
| ユーザー |
CELICA
|
| 提出日時 | 2020-10-12 05:10:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 217 ms / 2,000 ms |
| コード長 | 719 bytes |
| コンパイル時間 | 1,763 ms |
| コンパイル使用メモリ | 173,064 KB |
| 実行使用メモリ | 7,032 KB |
| 最終ジャッジ日時 | 2024-07-20 17:54:00 |
| 合計ジャッジ時間 | 4,998 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
priority_queue<ll> a;
ll sum{ 0 };
for (int i = 0; i < n; ++i)
{
int aa;
cin >> aa;
a.push(aa);
sum += aa;
}
int q;
cin >> q;
stringstream ss;
ll x, xold{ -1 };
for (int i = 0; i < q; ++i)
{
cin >> x;
if (sum && x > 1 && x != xold)
{
while (!a.empty() && a.top() >= x)
{
ll aa = a.top();
sum -= aa;
a.pop();
aa %= x;
a.push(aa);
sum += aa;
}
}
else if (x == 1)
sum = 0;
xold = x;
ss << sum << "\n";
}
cout << ss.str();
return 0;
}
CELICA