結果

問題 No.1012 荷物収集
ユーザー otamay6otamay6
提出日時 2019-11-05 23:16:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 178,508 KB
実行使用メモリ 12,108 KB
最終ジャッジ日時 2023-08-04 15:32:27
合計ジャッジ時間 10,400 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 229 ms
11,948 KB
testcase_05 AC 228 ms
11,812 KB
testcase_06 AC 232 ms
12,004 KB
testcase_07 AC 230 ms
11,936 KB
testcase_08 AC 233 ms
12,108 KB
testcase_09 AC 229 ms
11,860 KB
testcase_10 AC 231 ms
12,100 KB
testcase_11 AC 229 ms
11,864 KB
testcase_12 AC 231 ms
11,872 KB
testcase_13 AC 232 ms
11,976 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 170 ms
8,512 KB
testcase_25 AC 211 ms
10,360 KB
testcase_26 AC 90 ms
8,284 KB
testcase_27 AC 21 ms
4,380 KB
testcase_28 AC 196 ms
10,736 KB
testcase_29 AC 78 ms
8,980 KB
testcase_30 AC 199 ms
11,356 KB
testcase_31 AC 121 ms
5,344 KB
testcase_32 AC 80 ms
5,684 KB
testcase_33 AC 139 ms
6,264 KB
testcase_34 AC 156 ms
6,196 KB
testcase_35 AC 167 ms
9,660 KB
testcase_36 AC 152 ms
5,708 KB
testcase_37 AC 76 ms
8,764 KB
testcase_38 AC 175 ms
8,892 KB
testcase_39 AC 72 ms
5,888 KB
testcase_40 AC 94 ms
6,304 KB
testcase_41 AC 230 ms
11,624 KB
testcase_42 AC 117 ms
6,704 KB
testcase_43 AC 144 ms
8,664 KB
testcase_44 AC 2 ms
4,380 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> gutyoku(ll N,ll Q,vector<pair<ll,ll>> A,vector<ll> X){
    vector<ll> res;
    REP(q,Q){
        ll tmp=0;
        REP(i,N) tmp+=abs(A[i].first-X[q])*A[i].second;
        res.push_back(tmp);
    }
    return res;
}

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

int main(){
    ll N,Q;cin>>N>>Q;
    vector<pair<ll,ll>> A(N);
    REP(i,N) cin>>A[i].first>>A[i].second;
    vector<ll> X(Q);
    REP(i,Q) cin>>X[i];

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