結果

問題 No.1012 荷物収集
ユーザー pekempeypekempey
提出日時 2020-03-20 21:36:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 177,008 KB
実行使用メモリ 12,256 KB
最終ジャッジ日時 2023-08-21 15:40:42
合計ジャッジ時間 8,476 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 124 ms
11,648 KB
testcase_05 AC 122 ms
10,900 KB
testcase_06 AC 123 ms
11,640 KB
testcase_07 AC 123 ms
12,256 KB
testcase_08 AC 124 ms
11,164 KB
testcase_09 AC 124 ms
11,196 KB
testcase_10 AC 123 ms
11,996 KB
testcase_11 AC 123 ms
10,936 KB
testcase_12 AC 123 ms
11,004 KB
testcase_13 AC 123 ms
10,740 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 83 ms
6,996 KB
testcase_25 AC 111 ms
10,256 KB
testcase_26 AC 66 ms
6,412 KB
testcase_27 AC 17 ms
4,384 KB
testcase_28 AC 111 ms
10,016 KB
testcase_29 AC 74 ms
6,644 KB
testcase_30 AC 115 ms
9,496 KB
testcase_31 AC 43 ms
5,636 KB
testcase_32 AC 38 ms
4,660 KB
testcase_33 AC 56 ms
5,948 KB
testcase_34 AC 60 ms
6,868 KB
testcase_35 AC 97 ms
10,932 KB
testcase_36 AC 54 ms
6,792 KB
testcase_37 AC 70 ms
6,576 KB
testcase_38 AC 88 ms
7,128 KB
testcase_39 AC 41 ms
4,964 KB
testcase_40 AC 48 ms
5,888 KB
testcase_41 AC 123 ms
11,220 KB
testcase_42 AC 59 ms
6,500 KB
testcase_43 AC 82 ms
6,908 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  int N, Q; cin >> N >> Q;
  vector<ll> X(N), W(N);
  rep(i, N) cin >> X[i] >> W[i];
  vector<ll> Y(Q);
  const ll INF = 1e9;
  rep(i, Q) cin >> Y[i];
  Y.push_back(0);
  Y.push_back(INF);
  vector<pair<ll, int>> events;
  rep(i, N) events.emplace_back(X[i], i);
  rep(i, Q + 2) events.emplace_back(Y[i], i + N);
  sort(range(events));
  ll pos = 0;
  ll cost = 0;
  ll L = 0;
  ll R = 0;
  rep(i, N) {
    cost += X[i] * W[i];
    R += W[i];
  }
  vector<ll> ans(Q + 2);
  for (auto p : events) {
    cost += L * (p.first - pos);
    cost -= R * (p.first - pos);
    pos = p.first;
    if (p.second < N) {
      L += W[p.second];
      R -= W[p.second];
    } else {
      ans[p.second - N] = cost;
    }
  }
  rep(i, Q) cout << ans[i] << '\n';
}
0