結果

問題 No.1012 荷物収集
ユーザー MisterMister
提出日時 2020-05-02 02:02:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 89,320 KB
実行使用メモリ 6,708 KB
最終ジャッジ日時 2023-08-26 20:32:38
合計ジャッジ時間 8,863 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 165 ms
6,428 KB
testcase_05 AC 161 ms
6,640 KB
testcase_06 AC 161 ms
6,640 KB
testcase_07 AC 162 ms
6,552 KB
testcase_08 AC 165 ms
6,412 KB
testcase_09 AC 164 ms
6,416 KB
testcase_10 AC 163 ms
6,468 KB
testcase_11 AC 161 ms
6,544 KB
testcase_12 AC 163 ms
6,708 KB
testcase_13 AC 161 ms
6,552 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 124 ms
5,220 KB
testcase_25 AC 150 ms
6,024 KB
testcase_26 AC 53 ms
4,564 KB
testcase_27 AC 12 ms
4,380 KB
testcase_28 AC 135 ms
6,008 KB
testcase_29 AC 34 ms
4,704 KB
testcase_30 AC 130 ms
6,080 KB
testcase_31 AC 99 ms
4,384 KB
testcase_32 AC 59 ms
4,380 KB
testcase_33 AC 107 ms
4,564 KB
testcase_34 AC 125 ms
4,888 KB
testcase_35 AC 115 ms
5,476 KB
testcase_36 AC 125 ms
4,564 KB
testcase_37 AC 34 ms
4,572 KB
testcase_38 AC 127 ms
5,480 KB
testcase_39 AC 48 ms
4,376 KB
testcase_40 AC 70 ms
4,416 KB
testcase_41 AC 158 ms
6,128 KB
testcase_42 AC 85 ms
4,564 KB
testcase_43 AC 99 ms
5,072 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using lint = long long;

void solve() {
    int n, q;
    std::cin >> n >> q;

    std::vector<std::pair<lint, lint>> ps(n);
    for (auto& p : ps) std::cin >> p.first >> p.second;
    std::sort(ps.begin(), ps.end());

    std::vector<lint> xs(q);
    for (auto& x : xs) std::cin >> x;

    std::vector<int> qs(q);
    std::iota(qs.begin(), qs.end(), 0);
    std::sort(qs.begin(), qs.end(),
              [&](int i, int j) { return xs[i] < xs[j]; });

    lint psum = 0, bsum = 0,
         pw = 0, bw = 0;
    for (const auto& p : ps) {
        bsum += p.first * p.second;
        bw += p.second;
    }

    std::vector<lint> ans(q);
    int pi = 0;
    for (auto qi : qs) {
        lint x = xs[qi];

        while (pi < n && ps[pi].first < x) {
            auto sum = ps[pi].first * ps[pi].second;
            auto w = ps[pi].second;
            psum += sum, bsum -= sum;
            pw += w, bw -= w;
            ++pi;
        }

        ans[qi] = (pw * x - psum) + (bsum - bw * x);
    }

    for (auto a : ans) std::cout << a << std::endl;
}

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

    solve();

    return 0;
}
0