結果

問題 No.1012 荷物収集
ユーザー NOSSNOSS
提出日時 2020-03-20 22:01:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 1,913 ms
コンパイル使用メモリ 173,608 KB
実行使用メモリ 6,292 KB
最終ジャッジ日時 2023-08-21 16:35:01
合計ジャッジ時間 10,748 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 233 ms
6,212 KB
testcase_05 AC 231 ms
6,228 KB
testcase_06 AC 229 ms
6,180 KB
testcase_07 AC 232 ms
6,144 KB
testcase_08 AC 230 ms
6,192 KB
testcase_09 AC 231 ms
6,200 KB
testcase_10 AC 234 ms
6,144 KB
testcase_11 AC 236 ms
6,196 KB
testcase_12 AC 232 ms
6,292 KB
testcase_13 AC 231 ms
6,148 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 172 ms
4,564 KB
testcase_25 AC 221 ms
5,676 KB
testcase_26 AC 91 ms
5,236 KB
testcase_27 AC 21 ms
4,376 KB
testcase_28 AC 203 ms
6,040 KB
testcase_29 AC 76 ms
6,292 KB
testcase_30 AC 199 ms
6,264 KB
testcase_31 AC 120 ms
4,376 KB
testcase_32 AC 79 ms
4,380 KB
testcase_33 AC 142 ms
4,380 KB
testcase_34 AC 161 ms
4,380 KB
testcase_35 AC 171 ms
5,392 KB
testcase_36 AC 154 ms
4,380 KB
testcase_37 AC 75 ms
6,028 KB
testcase_38 AC 180 ms
4,868 KB
testcase_39 AC 75 ms
4,380 KB
testcase_40 AC 96 ms
4,376 KB
testcase_41 AC 240 ms
6,000 KB
testcase_42 AC 119 ms
4,380 KB
testcase_43 AC 146 ms
5,096 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<double,P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

int main(){
    int N, Q;
    cin >> N >> Q;
    vector<P> item(N);
    for(int i=0;i<N;i++){
        ll x, w;
        cin >> x >> w;
        item[i] = P(x,w);
    }
    sort(item.begin(), item.end());
    vector<ll> W(N+1), WX(N+1);
    for(int i=0;i<N;i++){
        W[i+1] = W[i] + item[i].second;
        WX[i+1] = WX[i] + item[i].first*item[i].second;
    }
    for(int t=0;t<Q;t++){
        ll x, ans = 0;
        cin >> x;
        int idx = lower_bound(item.begin(), item.end(), P(x,0)) - item.begin();
        ans = W[idx]*x - WX[idx] - ((W[N]-W[idx])*x - (WX[N]-WX[idx]));
        cout << ans << endl;
    }
    return 0;
}
0