結果
| 問題 |
No.885 アマリクエリ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-05 17:56:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 148 ms / 2,000 ms |
| コード長 | 577 bytes |
| コンパイル時間 | 2,581 ms |
| コンパイル使用メモリ | 199,464 KB |
| 最終ジャッジ日時 | 2025-01-15 02:57:05 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | int n; scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | rep(i,n) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
main.cpp:17:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | int q; scanf("%d",&q);
| ~~~~~^~~~~~~~~
main.cpp:19:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | int x; scanf("%d",&x);
| ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
int n; scanf("%d",&n);
vector<int> a(n);
rep(i,n) scanf("%d",&a[i]);
lint sum=accumulate(a.begin(),a.end(),0LL);
priority_queue<int> Q(a.begin(),a.end());
int q; scanf("%d",&q);
rep(_,q){
int x; scanf("%d",&x);
vector<int> next;
while(!Q.empty() && Q.top()>=x){
sum-=Q.top();
next.emplace_back(Q.top()%x);
Q.pop();
}
rep(i,next.size()){
sum+=next[i];
Q.emplace(next[i]);
}
printf("%lld\n",sum);
}
return 0;
}