結果

問題 No.1012 荷物収集
ユーザー t98slidert98slider
提出日時 2023-02-08 08:00:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 2,484 ms
コンパイル使用メモリ 172,960 KB
実行使用メモリ 7,192 KB
最終ジャッジ日時 2023-09-20 01:54:57
合計ジャッジ時間 10,060 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 44 ms
7,192 KB
testcase_05 AC 44 ms
7,076 KB
testcase_06 AC 43 ms
6,884 KB
testcase_07 AC 44 ms
6,880 KB
testcase_08 AC 44 ms
6,948 KB
testcase_09 AC 43 ms
6,924 KB
testcase_10 AC 44 ms
6,944 KB
testcase_11 AC 44 ms
6,980 KB
testcase_12 AC 44 ms
6,884 KB
testcase_13 AC 44 ms
7,080 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 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,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 40 ms
5,704 KB
testcase_25 AC 52 ms
6,160 KB
testcase_26 AC 30 ms
4,616 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 51 ms
6,152 KB
testcase_29 AC 31 ms
4,572 KB
testcase_30 AC 53 ms
6,260 KB
testcase_31 AC 23 ms
4,704 KB
testcase_32 AC 18 ms
4,380 KB
testcase_33 AC 28 ms
4,968 KB
testcase_34 AC 30 ms
5,112 KB
testcase_35 AC 44 ms
5,676 KB
testcase_36 AC 28 ms
5,100 KB
testcase_37 AC 30 ms
4,576 KB
testcase_38 AC 42 ms
5,696 KB
testcase_39 AC 20 ms
4,380 KB
testcase_40 AC 23 ms
4,428 KB
testcase_41 AC 58 ms
6,712 KB
testcase_42 AC 29 ms
4,888 KB
testcase_43 AC 38 ms
5,420 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<pair<ll,ll>> x(n + q);
    vector<ll> ans(q);
    ll ls = 0, lcnt = 0, rs = 0, rcnt = 0;
    for(int i = 0; i < n; i++){
        cin >> x[i].first >> x[i].second;
        rs += x[i].first * x[i].second;
        rcnt += x[i].second;
    }
    for(int i = 0; i < q; i++){
        cin >> x[i + n].first;
        x[i + n].second = -i;
    }
    sort(x.begin(), x.end());
    for(int i = 0; i < x.size(); i++){
        if(x[i].second <= 0){
            ans[-x[i].second] = x[i].first * lcnt - ls + rs - x[i].first * rcnt;
            continue;
        }
        rs -= x[i].first * x[i].second;
        rcnt -= x[i].second;
        ls += x[i].first * x[i].second;
        lcnt += x[i].second;
    }
    for(auto &&v:ans) cout << v << '\n';
}
0