結果
問題 |
No.1012 荷物収集
|
ユーザー |
![]() |
提出日時 | 2020-03-20 21:54:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,129 bytes |
コンパイル時間 | 1,879 ms |
コンパイル使用メモリ | 176,276 KB |
実行使用メモリ | 7,168 KB |
最終ジャッジ日時 | 2024-12-15 05:31:47 |
合計ジャッジ時間 | 5,682 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint n, q; cin >> n >> q; vector<pair<lint, lint>> xw(n); lint weight = 0; lint cost = 0; for (int i = 0; i < n; ++i) { cin >> xw[i].first >> xw[i].second; weight -= xw[i].second; cost += abs(xw[i].first - 1) * xw[i].second; } sort(xw.begin(), xw.end()); vector<pair<lint, lint>> y(q); for (int i = 0; i < q; ++i) { cin >> y[i].first; y[i].second = i; } sort(y.begin(), y.end()); vector<lint> ret(q); lint pos = 1; lint posx = 0; for (int i = 0; i < q; ++i) { while (posx < n && xw[posx].first < y[i].first) { cost += weight * (xw[posx].first - pos); weight += xw[posx].second * 2; pos = xw[posx].first; posx++; } ret[y[i].second] = cost + weight * (y[i].first - pos); } for (auto &r : ret) { cout << r << "\n"; } return 0; }