結果

問題 No.1012 荷物収集
ユーザー Strorkis
提出日時 2020-03-21 09:11:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 78,240 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-17 22:11:44
合計ジャッジ時間 6,490 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 11 WA * 30
権限があれば一括ダウンロードができます

ソースコード

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