結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 224 ms
7,076 KB
testcase_05 AC 219 ms
6,960 KB
testcase_06 AC 223 ms
7,000 KB
testcase_07 AC 219 ms
7,064 KB
testcase_08 AC 222 ms
6,916 KB
testcase_09 AC 222 ms
7,072 KB
testcase_10 AC 220 ms
6,956 KB
testcase_11 AC 222 ms
7,120 KB
testcase_12 AC 218 ms
7,248 KB
testcase_13 AC 218 ms
7,056 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,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 88 ms
5,208 KB
testcase_27 AC 20 ms
4,380 KB
testcase_28 AC 192 ms
6,176 KB
testcase_29 AC 71 ms
5,368 KB
testcase_30 AC 184 ms
6,436 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 161 ms
5,948 KB
testcase_36 RE -
testcase_37 AC 71 ms
5,268 KB
testcase_38 RE -
testcase_39 AC 68 ms
4,380 KB
testcase_40 RE -
testcase_41 AC 214 ms
6,428 KB
testcase_42 RE -
testcase_43 AC 140 ms
5,536 KB
testcase_44 AC 2 ms
4,376 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 < a.size() && 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 = a.size()-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