結果

問題 No.1012 荷物収集
ユーザー face4face4
提出日時 2020-07-06 17:01:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,017 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 79,676 KB
実行使用メモリ 7,664 KB
最終ジャッジ日時 2023-10-24 22:06:45
合計ジャッジ時間 8,688 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 237 ms
6,488 KB
testcase_05 AC 237 ms
6,488 KB
testcase_06 AC 238 ms
6,488 KB
testcase_07 AC 237 ms
6,488 KB
testcase_08 AC 239 ms
6,488 KB
testcase_09 AC 238 ms
6,488 KB
testcase_10 AC 237 ms
6,488 KB
testcase_11 AC 239 ms
6,488 KB
testcase_12 AC 239 ms
6,488 KB
testcase_13 AC 236 ms
6,488 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 178 ms
5,436 KB
testcase_25 AC 223 ms
7,664 KB
testcase_26 AC 95 ms
5,128 KB
testcase_27 AC 23 ms
4,348 KB
testcase_28 AC 205 ms
5,792 KB
testcase_29 AC 85 ms
5,656 KB
testcase_30 AC 203 ms
5,944 KB
testcase_31 AC 124 ms
4,516 KB
testcase_32 AC 81 ms
4,348 KB
testcase_33 AC 139 ms
4,816 KB
testcase_34 AC 156 ms
4,964 KB
testcase_35 AC 176 ms
5,640 KB
testcase_36 AC 156 ms
4,968 KB
testcase_37 AC 81 ms
5,656 KB
testcase_38 AC 180 ms
5,820 KB
testcase_39 AC 74 ms
4,424 KB
testcase_40 AC 97 ms
4,588 KB
testcase_41 AC 234 ms
6,152 KB
testcase_42 AC 122 ms
4,948 KB
testcase_43 AC 149 ms
5,192 KB
testcase_44 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

int main(){
    int n, q;
    cin >> n >> q;
    vector<pii> vp;
    for(int i = 0; i < n; i++){
        int x, w;
        cin >> x >> w;
        vp.push_back({x,w});
    }
    sort(vp.begin(), vp.end());
    vector<pii> ev;
    ev = vp;
    for(int i = 1; i <= q; i++){
        int x;
        cin >> x;
        ev.push_back({x, -i});
    }
    sort(ev.begin(), ev.end());
    int st = ev[0].first;
    ll tmp = 0, l = 0, r = 0;
    for(int i = 0; i < n; i++){
        tmp += (ll)(vp[i].first-st)*vp[i].second;
        r += vp[i].second;
    }
    vector<ll> ans(q+1);
    for(pii p : ev){
        int x = p.first, y = p.second;
        ll diff = x-st;
        tmp += diff*l - diff*r;
        if(y < 0){
            ans[-y] = tmp;
        }else{
            l += y;
            r -= y;
        }
        st = x;
    }
    for(int i = 1; i <= q; i++) cout << ans[i] << endl;
    return 0;
}
0