結果

問題 No.1012 荷物収集
ユーザー finefine
提出日時 2020-03-20 21:33:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 1,571 ms
コンパイル使用メモリ 176,952 KB
実行使用メモリ 9,736 KB
最終ジャッジ日時 2024-05-08 21:03:11
合計ジャッジ時間 5,587 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 46 ms
9,484 KB
testcase_05 AC 46 ms
9,604 KB
testcase_06 AC 46 ms
9,596 KB
testcase_07 AC 51 ms
9,736 KB
testcase_08 AC 44 ms
9,732 KB
testcase_09 AC 44 ms
9,604 KB
testcase_10 AC 45 ms
9,612 KB
testcase_11 AC 46 ms
9,612 KB
testcase_12 AC 46 ms
9,604 KB
testcase_13 AC 45 ms
9,612 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 39 ms
7,120 KB
testcase_25 AC 51 ms
9,188 KB
testcase_26 AC 29 ms
6,464 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 51 ms
9,188 KB
testcase_29 AC 30 ms
6,876 KB
testcase_30 AC 51 ms
9,336 KB
testcase_31 AC 22 ms
5,920 KB
testcase_32 AC 19 ms
5,376 KB
testcase_33 AC 28 ms
6,188 KB
testcase_34 AC 30 ms
6,324 KB
testcase_35 AC 43 ms
8,908 KB
testcase_36 AC 28 ms
6,196 KB
testcase_37 AC 29 ms
6,760 KB
testcase_38 AC 39 ms
7,352 KB
testcase_39 AC 18 ms
5,376 KB
testcase_40 AC 23 ms
6,156 KB
testcase_41 AC 56 ms
9,412 KB
testcase_42 AC 28 ms
6,208 KB
testcase_43 AC 37 ms
6,800 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;

    vector<ll> x(n), w(n);
    vector<P> v;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> w[i];
        v.emplace_back(x[i], i);
    }

    vector<ll> X(q);
    for (int i = 0; i < q; ++i) {
        cin >> X[i];
        v.emplace_back(X[i], i + n);
    }

    sort(v.begin(), v.end());

    vector<ll> ans(q, 0);
    ll sum = 0, ws = 0, px = 0;
    for (P& p : v) {
        if (p.second >= n) {
            if (px > 0) sum += (p.first - px) * ws;
            px = p.first;
            ans[p.second - n] += sum;
        } else {
            if (px > 0) sum += (p.first - px) * ws;
            ws += w[p.second];
            px = p.first;
        }
    }

    sum = 0, ws = 0, px = 0;
    reverse(v.begin(), v.end());
    for (P& p : v) {
        if (p.second >= n) {
            if (px > 0) sum += (px - p.first) * ws;
            px = p.first;
            ans[p.second - n] += sum;
        } else {
            if (px > 0) sum += (px - p.first) * ws;
            ws += w[p.second];
            px = p.first;
        }
    }

    for (int i = 0; i < q; ++i) {
        cout << ans[i] << "\n";
    }
    return 0;
}
0