結果

問題 No.1012 荷物収集
ユーザー Series_205Series_205
提出日時 2020-03-20 22:19:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,704 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 211,240 KB
実行使用メモリ 7,032 KB
最終ジャッジ日時 2023-08-21 17:04:40
合計ジャッジ時間 9,082 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 166 ms
6,948 KB
testcase_05 AC 169 ms
7,004 KB
testcase_06 AC 166 ms
6,932 KB
testcase_07 AC 170 ms
6,960 KB
testcase_08 AC 167 ms
6,968 KB
testcase_09 AC 168 ms
7,032 KB
testcase_10 AC 168 ms
7,000 KB
testcase_11 AC 168 ms
6,944 KB
testcase_12 AC 168 ms
7,024 KB
testcase_13 AC 167 ms
7,028 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,380 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,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 127 ms
5,708 KB
testcase_25 AC 152 ms
6,208 KB
testcase_26 AC 55 ms
4,596 KB
testcase_27 AC 12 ms
4,380 KB
testcase_28 AC 140 ms
6,240 KB
testcase_29 AC 36 ms
4,604 KB
testcase_30 AC 137 ms
6,232 KB
testcase_31 AC 101 ms
4,560 KB
testcase_32 AC 60 ms
4,384 KB
testcase_33 AC 111 ms
5,008 KB
testcase_34 AC 126 ms
5,092 KB
testcase_35 AC 115 ms
5,796 KB
testcase_36 AC 128 ms
5,088 KB
testcase_37 AC 36 ms
4,680 KB
testcase_38 AC 128 ms
5,624 KB
testcase_39 AC 50 ms
4,380 KB
testcase_40 AC 71 ms
4,380 KB
testcase_41 AC 162 ms
6,684 KB
testcase_42 AC 86 ms
4,896 KB
testcase_43 AC 101 ms
5,444 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    ll n, q;
    cin >> n >> q;
    using P = array<ll, 2>;
    V<P> w(n);
    rep(i, n) cin >> w[i][0] >> w[i][1];
    sort(ALL(w));
    V<ll> p(q), ans(q), x(q);
    rep(i, q) {
        cin >> x[i];
        p[i] = i;
    }
    sort(ALL(p), [&](ll a, ll b) { return x[a] < x[b]; });
    ll idx = 0;
    ll l = 0, r = 0;
    rep(i, n) {
        ans[p[0]] += abs(w[i][0] - x[p[0]]) * w[i][1];
        if(w[idx][0] < x[p[0]]) idx++;
        (w[i][0] < x[p[0]] ? l : r) += w[i][1];
    }
    ll sum = ans[p[0]];
    FOR(i, 1, q) {
        ll j = p[i];
        ll s = 0;
        while(idx < n && w[idx][0] < x[j]) {
            r -= w[idx][1];
            s += w[idx][1];
            sum -= abs(w[idx][0] - x[p[i - 1]]) * w[idx][1];
            sum += abs(w[idx][0] - x[j]) * w[idx][1];
            idx++;
        }
        sum += (l - r) * (x[j] - x[p[i - 1]]);
        l += s;
        ans[j] = sum;
    }
    for(ll a : ans)
        cout << a << endl;

    return 0;
}
0