結果

問題 No.1012 荷物収集
ユーザー otamay6otamay6
提出日時 2019-11-27 20:03:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 180,144 KB
実行使用メモリ 17,072 KB
最終ジャッジ日時 2024-04-22 13:13:23
合計ジャッジ時間 12,565 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 316 ms
16,944 KB
testcase_05 AC 314 ms
17,072 KB
testcase_06 AC 313 ms
16,948 KB
testcase_07 AC 321 ms
16,944 KB
testcase_08 AC 318 ms
16,944 KB
testcase_09 AC 317 ms
16,948 KB
testcase_10 AC 319 ms
16,944 KB
testcase_11 AC 315 ms
16,944 KB
testcase_12 AC 316 ms
16,948 KB
testcase_13 AC 314 ms
16,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 4 ms
6,940 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 241 ms
12,192 KB
testcase_25 AC 320 ms
14,696 KB
testcase_26 AC 143 ms
9,856 KB
testcase_27 AC 30 ms
6,940 KB
testcase_28 AC 302 ms
14,492 KB
testcase_29 AC 146 ms
11,648 KB
testcase_30 AC 306 ms
14,996 KB
testcase_31 AC 156 ms
8,840 KB
testcase_32 AC 103 ms
7,424 KB
testcase_33 AC 185 ms
9,864 KB
testcase_34 AC 209 ms
10,280 KB
testcase_35 AC 248 ms
12,544 KB
testcase_36 AC 208 ms
9,868 KB
testcase_37 AC 140 ms
11,008 KB
testcase_38 AC 249 ms
12,576 KB
testcase_39 AC 100 ms
7,424 KB
testcase_40 AC 128 ms
8,320 KB
testcase_41 AC 347 ms
15,716 KB
testcase_42 AC 164 ms
9,344 KB
testcase_43 AC 212 ms
11,264 KB
testcase_44 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<unistd.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

vector<ll> ans2(ll N,ll Q,vector<pair<ll,ll>> A,vector<ll> X){
    vector<ll> x(N+1,0),w(N+1,0),Sxw(N+2,0),Sw(N+2,0);
    sort(All(A));
    REP(i,N){
        x[i+1]=A[i].first;
        w[i+1]=A[i].second;
    }
    REP(i,N+1){
        Sxw[i+1]=Sxw[i]+x[i]*w[i];
        Sw[i+1]=Sw[i]+w[i];
    }
    vector<ll> res;
    REP(q,Q){
        int k=lower_bound(All(x),X[q])-x.begin();
        res.push_back(Sxw[N+1]-2*Sxw[k]+X[q]*(2*Sw[k]-Sw[N+1]));
    }
    return res;
}

int main(){
    ll N,Q;cin>>N>>Q;
    assert(1<=N&&N<=100000);
    assert(1<=Q&&Q<=100000);
    vector<pair<ll,ll>> A(N);
    set<int> appeared;
    REP(i,N){
        cin>>A[i].first>>A[i].second;
        assert(1<=A[i].first&&A[i].first<=1000000000);
        assert(1<=A[i].second&&A[i].second<=10000);
        assert(!appeared.count(A[i].first));
        appeared.insert(A[i].first);
    }
    appeared.clear();
    vector<ll> X(Q);
    REP(i,Q){
        cin>>X[i];
        assert(1<=X[i]&&X[i]<=1000000000);
        assert(!appeared.count(X[i]));
        appeared.insert(X[i]);
    }

    vector<ll> ans=ans2(N,Q,A,X);
    REP(i,Q){
        cout<<ans[i]<<endl;
    }
}
0