結果

問題 No.1012 荷物収集
ユーザー face4face4
提出日時 2020-07-06 17:05:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,066 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 80,316 KB
実行使用メモリ 6,592 KB
最終ジャッジ日時 2023-10-24 22:07:31
合計ジャッジ時間 8,423 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 166 ms
6,400 KB
testcase_05 AC 165 ms
6,400 KB
testcase_06 AC 166 ms
6,400 KB
testcase_07 AC 165 ms
6,400 KB
testcase_08 AC 166 ms
6,400 KB
testcase_09 AC 167 ms
6,400 KB
testcase_10 AC 166 ms
6,400 KB
testcase_11 AC 164 ms
6,400 KB
testcase_12 AC 164 ms
6,400 KB
testcase_13 AC 166 ms
6,400 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 3 ms
4,372 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 3 ms
4,372 KB
testcase_18 AC 3 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 3 ms
4,372 KB
testcase_22 AC 3 ms
4,372 KB
testcase_23 AC 2 ms
4,372 KB
testcase_24 AC 129 ms
5,340 KB
testcase_25 AC 155 ms
6,592 KB
testcase_26 AC 56 ms
5,032 KB
testcase_27 AC 14 ms
4,372 KB
testcase_28 AC 141 ms
5,704 KB
testcase_29 AC 41 ms
5,560 KB
testcase_30 AC 137 ms
5,856 KB
testcase_31 AC 101 ms
4,428 KB
testcase_32 AC 60 ms
4,372 KB
testcase_33 AC 109 ms
4,720 KB
testcase_34 AC 125 ms
4,876 KB
testcase_35 AC 117 ms
5,552 KB
testcase_36 AC 125 ms
4,880 KB
testcase_37 AC 40 ms
5,560 KB
testcase_38 AC 128 ms
5,724 KB
testcase_39 AC 50 ms
4,372 KB
testcase_40 AC 71 ms
4,492 KB
testcase_41 AC 164 ms
6,064 KB
testcase_42 AC 88 ms
4,852 KB
testcase_43 AC 100 ms
5,104 KB
testcase_44 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    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