結果

問題 No.885 アマリクエリ
コンテスト
ユーザー kagamiz
提出日時 2021-05-22 21:14:36
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 774 ms / 2,000 ms
コード長 525 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 408 ms
コンパイル使用メモリ 58,368 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2026-04-27 00:30:28
合計ジャッジ時間 4,511 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <set>

using namespace std;

int main()
{
	int N;
	scanf("%d", &N);
	
	long long sum = 0;
	multiset<int> ms;
	for (int i = 0; i < N; i++) {
		int x;
		scanf("%d", &x);
		ms.insert(x);
		sum += x;
	}
	
	int Q;
	scanf("%d", &Q);
	
	for (int i = 0; i < Q; i++) {
		int m;
		scanf("%d", &m);
		multiset<int>::iterator it;
		while ((it = ms.lower_bound(m)) != ms.end()) {
			int val = *it;
			sum += (val % m) - val;
			ms.erase(it);
			ms.insert(val % m);
		}
		printf("%lld\n", sum);
	}
	
	return 0;
}
0