結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, q;
    cin >> n >> q;

    vector<int> x(n), w(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> w[i];
    }

    vector<ll> s0(n + 1), w0(n + 1);
    for (int i = 0; i < n; i++) {
        s0[i + 1] = s0[i] + (ll)x[i] * w[i];
        w0[i + 1] = w0[i] + w[i];
    }

    for (int _ = 0; _ < q; _++) {
        int X;
        cin >> X;

        int k = lower_bound(x.begin(), x.end(), X) - x.begin();
        ll r = -s0[k] + X * w0[k] + (s0[n] - s0[k]) - X * (w0[n] - w0[k]);
        cout << r << '\n';
    }

    return 0;
}
0