結果
| 問題 |
No.1012 荷物収集
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-25 15:31:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 859 bytes |
| コンパイル時間 | 2,237 ms |
| コンパイル使用メモリ | 204,844 KB |
| 最終ジャッジ日時 | 2025-01-12 05:29:50 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | int n,q; scanf("%d%d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
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("%lld%lld",&x[i],&w[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | rep(i,q) scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#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,q; scanf("%d%d",&n,&q);
vector<lint> x(n),w(n);
rep(i,n) scanf("%lld%lld",&x[i],&w[i]);
vector<lint> a(q);
rep(i,q) scanf("%lld",&a[i]);
vector<int> p(q);
iota(p.begin(),p.end(),0);
sort(p.begin(),p.end(),[&](int i,int j){ return a[i]<a[j]; });
lint cost_L=0,cost_R=0,wsum_L=0,wsum_R=0;
set<pair<lint,lint>> L,R;
rep(i,n){
R.emplace(x[i],w[i]);
cost_R+=w[i]*x[i];
wsum_R+=w[i];
}
vector<lint> ans(q);
for(int i:p){
while(!R.empty() && R.begin()->first<a[i]){
auto [x0,w0]=*R.begin();
R.erase(R.begin());
cost_R-=w0*x0;
wsum_R-=w0;
L.emplace(x0,w0);
cost_L+=w0*x0;
wsum_L+=w0;
}
ans[i]=(cost_R-wsum_R*a[i])+(wsum_L*a[i]-cost_L);
}
rep(i,q) printf("%lld\n",ans[i]);
return 0;
}