結果

問題 No.1012 荷物収集
ユーザー kibunakibuna
提出日時 2020-03-20 21:54:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 172,228 KB
実行使用メモリ 7,212 KB
最終ジャッジ日時 2023-08-21 16:20:26
合計ジャッジ時間 6,087 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 46 ms
6,924 KB
testcase_05 AC 47 ms
7,040 KB
testcase_06 AC 46 ms
7,028 KB
testcase_07 AC 46 ms
7,004 KB
testcase_08 AC 47 ms
6,956 KB
testcase_09 AC 47 ms
7,032 KB
testcase_10 AC 46 ms
6,920 KB
testcase_11 AC 46 ms
7,212 KB
testcase_12 AC 46 ms
7,080 KB
testcase_13 AC 46 ms
7,040 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 39 ms
5,768 KB
testcase_25 AC 52 ms
6,244 KB
testcase_26 AC 29 ms
4,600 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 50 ms
6,184 KB
testcase_29 AC 30 ms
4,684 KB
testcase_30 AC 51 ms
6,124 KB
testcase_31 AC 23 ms
4,620 KB
testcase_32 AC 18 ms
4,376 KB
testcase_33 AC 28 ms
4,896 KB
testcase_34 AC 30 ms
5,124 KB
testcase_35 AC 44 ms
5,608 KB
testcase_36 AC 28 ms
5,156 KB
testcase_37 AC 29 ms
4,796 KB
testcase_38 AC 42 ms
5,684 KB
testcase_39 AC 19 ms
4,376 KB
testcase_40 AC 23 ms
4,380 KB
testcase_41 AC 57 ms
6,392 KB
testcase_42 AC 28 ms
4,920 KB
testcase_43 AC 38 ms
5,420 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, q;
    cin >> n >> q;
    vector<pair<lint, lint>> xw(n);
    lint weight = 0;
    lint cost   = 0;
    for (int i = 0; i < n; ++i) {
        cin >> xw[i].first >> xw[i].second;
        weight -= xw[i].second;
        cost += abs(xw[i].first - 1) * xw[i].second;
    }
    sort(xw.begin(), xw.end());

    vector<pair<lint, lint>> y(q);
    for (int i = 0; i < q; ++i) {
        cin >> y[i].first;
        y[i].second = i;
    }
    sort(y.begin(), y.end());
    vector<lint> ret(q);
    lint pos  = 1;
    lint posx = 0;
    for (int i = 0; i < q; ++i) {
        while (posx < n && xw[posx].first < y[i].first) {
            cost += weight * (xw[posx].first - pos);
            weight += xw[posx].second * 2;
            pos = xw[posx].first;
            posx++;
        }
        ret[y[i].second] = cost + weight * (y[i].first - pos);
    }
    for (auto &r : ret) {
        cout << r << "\n";
    }
    return 0;
}
0