結果
問題 | No.1012 荷物収集 |
ユーザー |
![]() |
提出日時 | 2020-03-21 04:04:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 1,155 bytes |
コンパイル時間 | 1,065 ms |
コンパイル使用メモリ | 98,228 KB |
実行使用メモリ | 6,016 KB |
最終ジャッジ日時 | 2024-12-16 08:44:00 |
合計ジャッジ時間 | 6,939 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
/* -*- coding: utf-8 -*- * * 1012.cc: No.1012 荷物収集 - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef long long ll; typedef pair<int,int> pii; /* global variables */ pii ps[MAX_N]; ll xwss[MAX_N + 1], wss[MAX_N + 1]; /* subroutines */ /* main */ int main() { int n, q; scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) scanf("%d%d", &ps[i].first, &ps[i].second); sort(ps, ps + n); for (int i = 0; i < n; i++) { xwss[i + 1] = xwss[i] + (ll)ps[i].first * ps[i].second; wss[i + 1] = wss[i] + ps[i].second; } while (q--) { int xq; scanf("%d", &xq); int k = lower_bound(ps, ps + n, pii(xq, 0)) - ps; ll sum = (xwss[n] - xwss[k] - (wss[n] - wss[k]) * xq) + (wss[k] * xq - xwss[k]); printf("%lld\n", sum); } return 0; }