結果
| 問題 |
No.1012 荷物収集
|
| コンテスト | |
| ユーザー |
rniya
|
| 提出日時 | 2020-03-20 21:54:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 2,000 ms |
| コード長 | 813 bytes |
| コンパイル時間 | 2,081 ms |
| コンパイル使用メモリ | 176,408 KB |
| 実行使用メモリ | 9,884 KB |
| 最終ジャッジ日時 | 2024-12-15 05:33:39 |
| 合計ジャッジ時間 | 6,113 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,Q; cin >> N >> Q;
vector<ll> x(N),w(N);
for (int i=0;i<N;++i) cin >> x[i] >> w[i];
vector<ll> X(Q);
for (int i=0;i<Q;++i) cin >> X[i];
vector<pair<ll,ll>> pos;
for (int i=0;i<N;++i) pos.emplace_back(x[i],w[i]);
for (int i=0;i<Q;++i) pos.emplace_back(X[i],-i);
sort(pos.begin(),pos.end());
ll now=0,last=0,cnt=0,sum=0;
for (int i=0;i<N;++i) now+=x[i]*w[i],sum+=w[i];
vector<ll> ans(Q);
for (auto p:pos){
int y=p.first,id=p.second;
now+=cnt*(y-last);
now-=(sum-cnt)*(y-last);
if (id>0) cnt+=id;
else ans[-id]=now;
last=y;
}
for (int i=0;i<Q;++i) cout << ans[i] << '\n';
}
rniya