結果

問題 No.1012 荷物収集
ユーザー StrorkisStrorkis
提出日時 2020-03-21 09:11:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 77,796 KB
実行使用メモリ 6,368 KB
最終ジャッジ日時 2023-08-22 20:33:00
合計ジャッジ時間 6,504 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 50 ms
6,208 KB
testcase_05 AC 50 ms
6,248 KB
testcase_06 AC 50 ms
6,144 KB
testcase_07 AC 50 ms
6,196 KB
testcase_08 AC 50 ms
6,212 KB
testcase_09 AC 50 ms
6,280 KB
testcase_10 AC 50 ms
6,136 KB
testcase_11 AC 50 ms
6,232 KB
testcase_12 AC 50 ms
6,364 KB
testcase_13 AC 50 ms
6,216 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, Q; cin >> N >> Q;
    vector<P> xw(N+1);
    xw[0] = P(0, 0);
    vector<ll> csW(N+1);
    for (int i = 1; i <= N; i++) {
        int x, w; cin >> x >> w;
        xw[i] = P(x, w);
        csW[i] = csW[i-1] + w;
    }
    sort(xw.begin(), xw.end());
    vector<ll> csXW(N+1);
    for (int i = 1; i <= N; i++) {
        csXW[i] = csXW[i-1] + xw[i].first * xw[i].second;
    }

    for (int i = 0; i < Q; i++) {
        int X; cin >> X;
        int left = 0, right = N+1;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            if (xw[mid].first <= X)
                left = mid;
            else
                right = mid;
        }
        ll ans = 0;
        ans += csXW.back() - 2 * csXW[left];
        ans += 2 * X * csW[left] - X * csW.back();
        cout << ans << "\n";
    }
}
0