結果

問題 No.1012 荷物収集
ユーザー 夜
提出日時 2021-03-02 20:12:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 1,748 bytes
コンパイル時間 1,072 ms
コンパイル使用メモリ 102,016 KB
実行使用メモリ 8,908 KB
最終ジャッジ日時 2024-04-14 04:52:19
合計ジャッジ時間 10,755 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 241 ms
8,776 KB
testcase_05 AC 244 ms
8,780 KB
testcase_06 AC 242 ms
8,908 KB
testcase_07 AC 243 ms
8,784 KB
testcase_08 AC 240 ms
8,828 KB
testcase_09 AC 240 ms
8,776 KB
testcase_10 AC 240 ms
8,780 KB
testcase_11 AC 242 ms
8,780 KB
testcase_12 AC 240 ms
8,784 KB
testcase_13 AC 244 ms
8,848 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 4 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 188 ms
6,940 KB
testcase_25 AC 235 ms
7,892 KB
testcase_26 AC 108 ms
7,500 KB
testcase_27 AC 26 ms
6,944 KB
testcase_28 AC 222 ms
7,888 KB
testcase_29 AC 101 ms
6,944 KB
testcase_30 AC 220 ms
8,676 KB
testcase_31 AC 127 ms
6,988 KB
testcase_32 AC 85 ms
6,940 KB
testcase_33 AC 144 ms
6,944 KB
testcase_34 AC 161 ms
6,944 KB
testcase_35 AC 187 ms
7,252 KB
testcase_36 AC 160 ms
6,944 KB
testcase_37 AC 96 ms
6,940 KB
testcase_38 AC 191 ms
7,376 KB
testcase_39 AC 81 ms
6,944 KB
testcase_40 AC 104 ms
6,940 KB
testcase_41 AC 252 ms
8,644 KB
testcase_42 AC 129 ms
6,940 KB
testcase_43 AC 163 ms
7,756 KB
testcase_44 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
pair<long long, long long> p[100010], x[100010];
long long ans[100010] = {};
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> que;
int main() {
    int n, q;
    long long l = 0, r = 0;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        long long x, w;
        cin >> x >> w;
        r += w;
        p[i] = { x,w };
        que.push({ x,w });
    }
    sort(p, p + n);
    for (int i = 0; i < q; i++) {
        long long X;
        cin >> X;
        x[i] = { X,i };
    }
    sort(x, x + q);
    for (int i = 0; i < n; i++) {
        ans[x[0].second] += abs(p[i].first - x[0].first) * p[i].second;
    }
    while (!que.empty()) {
        if (que.top().first > x[0].first)break;
        l += que.top().second, r -= que.top().second;
        que.pop();
    }
    for (int i = 1; i < q; i++) {
        ans[x[i].second] = ans[x[i - 1].second];
        long long co = 0;
        while (!que.empty()) {
            if (que.top().first > x[i].first)break;
            ans[x[i].second] -= abs(x[i - 1].first - que.top().first) * que.top().second;
            ans[x[i].second] += abs(x[i].first - que.top().first) * que.top().second;
            co += que.top().second, r -= que.top().second;
            que.pop();
        }
        ans[x[i].second] += (x[i].first - x[i - 1].first) * (l - r);
        l += co;
    }
    for (int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
}
0