結果

問題 No.1012 荷物収集
ユーザー t98slider
提出日時 2023-02-08 08:00:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 174,420 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-07-05 22:15:04
合計ジャッジ時間 5,707 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

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