結果

問題 No.1012 荷物収集
ユーザー MayimgMayimg
提出日時 2020-07-07 09:48:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,097 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 214,672 KB
実行使用メモリ 18,140 KB
最終ジャッジ日時 2023-10-26 00:00:10
合計ジャッジ時間 11,498 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 68 ms
18,140 KB
testcase_05 AC 67 ms
18,140 KB
testcase_06 AC 68 ms
18,140 KB
testcase_07 AC 68 ms
18,140 KB
testcase_08 AC 68 ms
18,140 KB
testcase_09 AC 68 ms
18,140 KB
testcase_10 AC 68 ms
18,140 KB
testcase_11 AC 69 ms
18,140 KB
testcase_12 AC 68 ms
18,140 KB
testcase_13 AC 68 ms
18,140 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 64 ms
12,456 KB
testcase_25 AC 86 ms
16,292 KB
testcase_26 AC 47 ms
10,340 KB
testcase_27 AC 11 ms
4,804 KB
testcase_28 AC 88 ms
16,028 KB
testcase_29 AC 50 ms
10,604 KB
testcase_30 AC 89 ms
16,028 KB
testcase_31 AC 35 ms
9,552 KB
testcase_32 AC 28 ms
7,552 KB
testcase_33 AC 46 ms
10,344 KB
testcase_34 AC 51 ms
10,872 KB
testcase_35 AC 74 ms
14,912 KB
testcase_36 AC 45 ms
10,608 KB
testcase_37 AC 47 ms
10,340 KB
testcase_38 AC 69 ms
12,984 KB
testcase_39 AC 30 ms
7,548 KB
testcase_40 AC 36 ms
9,288 KB
testcase_41 AC 99 ms
17,084 KB
testcase_42 AC 44 ms
10,344 KB
testcase_43 AC 59 ms
11,924 KB
testcase_44 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<vector<int>> v;
  for (int i = 0; i < n; i++) {
    int x, w;
    cin >> x >> w;
    v.push_back({x, w, 0});
  }
  v.push_back({0, 0, 0});
  v.push_back({(int) 1e9 + 1, 0, 0});
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    v.push_back({x, i, 1});
  }
  sort(v.begin(), v.end());
  vector<long long> pref((int) v.size());
  vector<long long> ans(q);
  long long w_tot = 0;
  for (int i = 1; i < (int) v.size(); i++) {
    pref[i] = pref[i - 1] + w_tot * (v[i][0] - v[i - 1][0]);
    if (v[i][2] == 0) {
      w_tot += v[i][1];
    } else {
      ans[v[i][1]] += pref[i];
    }
  }
  vector<long long> suff((int) v.size());
  w_tot = 0;
  for (int i = (int) v.size() - 2; i >= 1; i--) {
    suff[i] = suff[i + 1] + w_tot * (v[i + 1][0] - v[i][0]);
    if (v[i][2] == 0) {
      w_tot += v[i][1];
    } else {
      ans[v[i][1]] += suff[i];
    }
  }
  for (auto& p : ans) {
    cout << p << '\n';
  }
  return 0;
}
0