結果

問題 No.1012 荷物収集
ユーザー merom686merom686
提出日時 2020-03-20 22:18:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 954 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 80,692 KB
実行使用メモリ 5,456 KB
最終ジャッジ日時 2023-08-21 17:02:42
合計ジャッジ時間 5,148 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 41 ms
5,368 KB
testcase_05 AC 41 ms
5,352 KB
testcase_06 AC 40 ms
5,440 KB
testcase_07 AC 41 ms
5,340 KB
testcase_08 AC 40 ms
5,456 KB
testcase_09 AC 40 ms
5,348 KB
testcase_10 AC 41 ms
5,400 KB
testcase_11 AC 40 ms
5,384 KB
testcase_12 AC 40 ms
5,400 KB
testcase_13 AC 41 ms
5,392 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 39 ms
4,384 KB
testcase_25 AC 51 ms
4,912 KB
testcase_26 AC 27 ms
4,644 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 51 ms
5,124 KB
testcase_29 AC 29 ms
5,340 KB
testcase_30 AC 52 ms
5,376 KB
testcase_31 AC 20 ms
4,380 KB
testcase_32 AC 18 ms
4,376 KB
testcase_33 AC 27 ms
4,380 KB
testcase_34 AC 29 ms
4,376 KB
testcase_35 AC 43 ms
4,924 KB
testcase_36 AC 25 ms
4,384 KB
testcase_37 AC 28 ms
5,184 KB
testcase_38 AC 41 ms
4,388 KB
testcase_39 AC 18 ms
4,380 KB
testcase_40 AC 22 ms
4,384 KB
testcase_41 AC 57 ms
5,396 KB
testcase_42 AC 27 ms
4,380 KB
testcase_43 AC 37 ms
4,744 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P& p) const {
        return x < p.x;
    }
    int x, w;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int x, w;
        cin >> x >> w;
        p[i] = { x, w };
    }
    sort(p.begin(), p.end());

    vector<ll> s0(n + 1), w0(n + 1);
    for (int i = 0; i < n; i++) {
        s0[i + 1] = s0[i] + (ll)p[i].x * p[i].w;
        w0[i + 1] = w0[i] + p[i].w;
    }

    for (int _ = 0; _ < q; _++) {
        int x;
        cin >> x;

        int k = lower_bound(p.begin(), p.end(), P{ x, 0 }) - p.begin();
        ll r = -s0[k] + x * w0[k] + (s0[n] - s0[k]) - x * (w0[n] - w0[k]);
        cout << r << '\n';
    }

    return 0;
}
0