結果

問題 No.885 アマリクエリ
ユーザー otoshigootoshigo
提出日時 2024-04-23 14:30:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 816 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 200,552 KB
実行使用メモリ 10,432 KB
最終ジャッジ日時 2024-04-23 14:30:48
合計ジャッジ時間 6,321 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 816 ms
9,920 KB
testcase_01 AC 242 ms
10,432 KB
testcase_02 AC 96 ms
8,704 KB
testcase_03 AC 92 ms
9,728 KB
testcase_04 AC 89 ms
9,728 KB
testcase_05 AC 54 ms
8,832 KB
testcase_06 AC 46 ms
8,832 KB
testcase_07 AC 41 ms
8,704 KB
testcase_08 AC 21 ms
5,376 KB
testcase_09 AC 247 ms
10,308 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	vector<ll>A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	int Q;
	cin>>Q;
	ll sum=0;
	multiset<ll>se;
	for(int i=0;i<N;i++){
		sum+=A[i];
		se.insert(-A[i]);
	}
	while(Q--){
		ll X;
		cin>>X;
		vector<ll>V;
		while(se.size()&&X<=-*se.begin()){
			ll a=-*se.begin();
			sum-=a;
			se.erase(se.find(-a));
			sum+=a%X;
			V.push_back(a%X);
		}
		for(auto x:V)se.insert(-x);
		cout<<sum<<"\n";
	}
}
0