結果

問題 No.1012 荷物収集
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-06-21 01:24:59
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,474 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 152,952 KB
実行使用メモリ 7,112 KB
最終ジャッジ日時 2023-09-16 17:56:47
合計ジャッジ時間 12,035 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 224 ms
7,000 KB
testcase_05 AC 224 ms
7,060 KB
testcase_06 AC 228 ms
7,000 KB
testcase_07 AC 218 ms
7,112 KB
testcase_08 AC 221 ms
6,944 KB
testcase_09 AC 221 ms
6,992 KB
testcase_10 AC 225 ms
7,096 KB
testcase_11 AC 218 ms
7,060 KB
testcase_12 AC 225 ms
7,048 KB
testcase_13 AC 225 ms
6,996 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 87 ms
4,984 KB
testcase_27 AC 21 ms
4,376 KB
testcase_28 AC 192 ms
6,152 KB
testcase_29 AC 71 ms
5,412 KB
testcase_30 AC 188 ms
6,464 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 158 ms
5,628 KB
testcase_36 RE -
testcase_37 AC 72 ms
5,236 KB
testcase_38 RE -
testcase_39 AC 69 ms
4,380 KB
testcase_40 RE -
testcase_41 AC 220 ms
6,512 KB
testcase_42 RE -
testcase_43 AC 137 ms
5,356 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.21 01:22:47
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n,q;cin >> n >> q;
    vector<pair<int,int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());
    vector<pair<int,int>> query(q);
    for (int i = 0; i < q; i++) {
        cin >> query[i].first;
        query[i].second = i;
    }
    sort(query.begin(), query.end());
    vector<ll> sum1(n),sum2(n);
    int now = 0;
    ll weight = 0;
    for (int i = 0; i < q; i++) {
        if (i > 0) sum1[i] = sum1[i-1] + weight * (query[i].first - query[i-1].first);
        while(now < n && a[now].first <= query[i].first) {
            weight += a[now].second;
            sum1[i] += ll(query[i].first - a[now].first) * a[now].second;
            now++;
        }
    }
    weight = 0;
    now = n-1;
    for (int i = q-1; i >= 0; i--) {
        if (i + 1 < q) sum2[i] = sum2[i+1] + weight * (query[i+1].first - query[i].first);
        while(now >= 0 && a[now].first >= query[i].first) {
            weight += a[now].second;
            sum2[i] += ll(a[now].first - query[i].first) * a[now].second;
            now--;
        }
    }
    vector<ll> ans(q);
    for (int i = 0; i < q; i++) {
        ans[query[i].second] = sum1[i] + sum2[i];
    }
    for (int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}
0