結果

問題 No.1012 荷物収集
ユーザー taklimonetaklimone
提出日時 2020-03-21 15:59:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,171 bytes
コンパイル時間 2,712 ms
コンパイル使用メモリ 208,016 KB
実行使用メモリ 7,964 KB
最終ジャッジ日時 2023-08-24 16:37:57
合計ジャッジ時間 8,637 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 46 ms
7,964 KB
testcase_05 AC 46 ms
7,936 KB
testcase_06 AC 46 ms
7,740 KB
testcase_07 AC 45 ms
7,804 KB
testcase_08 AC 46 ms
7,844 KB
testcase_09 AC 46 ms
7,848 KB
testcase_10 AC 46 ms
7,916 KB
testcase_11 AC 46 ms
7,796 KB
testcase_12 AC 46 ms
7,852 KB
testcase_13 AC 45 ms
7,808 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 44 ms
5,372 KB
testcase_25 AC 58 ms
6,748 KB
testcase_26 AC 31 ms
6,512 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 57 ms
7,304 KB
testcase_29 AC 33 ms
7,644 KB
testcase_30 AC 58 ms
7,836 KB
testcase_31 WA -
testcase_32 AC 19 ms
4,380 KB
testcase_33 AC 29 ms
4,380 KB
testcase_34 AC 31 ms
4,380 KB
testcase_35 AC 48 ms
6,692 KB
testcase_36 WA -
testcase_37 AC 31 ms
7,432 KB
testcase_38 AC 46 ms
5,896 KB
testcase_39 AC 20 ms
4,592 KB
testcase_40 AC 24 ms
4,676 KB
testcase_41 AC 64 ms
7,508 KB
testcase_42 AC 31 ms
5,000 KB
testcase_43 AC 41 ms
6,192 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

    int N, Q; cin >> N >> Q;
    vector<pair<long long, long long>> x(N + 1);
    for(int i=1; i<=N; ++i) cin >> x[i].first >> x[i].second;
    sort(begin(x), end(x));

    vector<long long> L(N + 1, 0), Lsum(N + 1, 0);
    for(int i=1; i<=N; ++i) Lsum[i] = Lsum[i - 1] + x[i].second;
    for(int i=2; i<=N; ++i) L[i] = L[i - 1] + Lsum[i - 1] * (x[i].first - x[i - 1].first);

    vector<long long> R(N + 2, 0), Rsum(N + 1, 0);
    for(int i=N; i>=1; --i) Rsum[i] = Rsum[i + 1] + x[i].second;
    for(int i=N-1; i>=1; --i) R[i] = R[i + 1] + Rsum[i + 1] * (x[i + 1].first - x[i].first);

    while(Q--) {
        long long X; cin >> X;
        int k = upper_bound(begin(x) + 1, end(x), pair<long long, long long>(X, 0)) - begin(x);
        if(k == 1) {
            cout << R[1] + Rsum[1] * (x[1].first - X) << '\n';
        } else if(k == N + 1) {
            cout << L[N] + Lsum[N] * (X - x[N].first) << '\n';
        } else {
            cout << L[k - 1] + Lsum[k - 1] * (X - x[k - 1].first) + R[k] + Rsum[k] * (x[k].first - X) << '\n';
        }
    }
}
0