結果
問題 |
No.1012 荷物収集
|
ユーザー |
![]() |
提出日時 | 2020-03-20 22:01:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 222 ms / 2,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 1,782 ms |
コンパイル使用メモリ | 176,432 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-15 05:49:17 |
合計ジャッジ時間 | 8,913 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; using P = pair<ll, ll>; using P3 = pair<double,P>; using PP = pair<P, P>; constexpr int INF = 1 << 30; constexpr ll MOD = ll(1e9)+7; constexpr int di[] = {0, 1, 0, -1}; constexpr int dj[] = {1, 0, -1, 0}; constexpr double EPS = 1e-9; int main(){ int N, Q; cin >> N >> Q; vector<P> item(N); for(int i=0;i<N;i++){ ll x, w; cin >> x >> w; item[i] = P(x,w); } sort(item.begin(), item.end()); vector<ll> W(N+1), WX(N+1); for(int i=0;i<N;i++){ W[i+1] = W[i] + item[i].second; WX[i+1] = WX[i] + item[i].first*item[i].second; } for(int t=0;t<Q;t++){ ll x, ans = 0; cin >> x; int idx = lower_bound(item.begin(), item.end(), P(x,0)) - item.begin(); ans = W[idx]*x - WX[idx] - ((W[N]-W[idx])*x - (WX[N]-WX[idx])); cout << ans << endl; } return 0; }