結果

問題 No.885 アマリクエリ
ユーザー QCFiumQCFium
提出日時 2019-06-25 21:23:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 747 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 65,024 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-05 13:00:40
合計ジャッジ時間 4,067 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
4,376 KB
testcase_01 AC 78 ms
4,376 KB
testcase_02 AC 23 ms
4,376 KB
testcase_03 AC 20 ms
4,376 KB
testcase_04 AC 20 ms
4,376 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 11 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 78 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,500 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <queue>
#include <iostream>

#ifdef _WIN32
#define getchar_fast _getchar_nolock
#else
#define getchar_fast getchar_unlocked
#endif
int ri() {
	int r = 0, c, s = 0;
	for (;;) {c=getchar_fast(); if (c == '-') { s = 1; break; } if (c <= '9' && c >= '0') { r = c - '0'; break; } }
	for (;;) {c=getchar_fast(); if (c < '0' || c > '9') break; r = r * 10 + c - '0'; }
	if (s) r = -r;
	return r;
}

int main() {
	int n = ri();
	std::priority_queue<int> que;
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		int a = ri();
		sum += a;
		que.push(a);
	}
	int q = ri();
	for (int i = 0; i < q; i++) {
		int x = ri();
		int t;
		while ((t = que.top()) >= x) sum -= t - t % x, que.pop(), que.push(t % x);
		printf("%lld\n", sum);
	}
	
	return 0;
}
0