結果

問題 No.1012 荷物収集
ユーザー outlineoutline
提出日時 2021-02-11 00:43:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,779 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 141,632 KB
実行使用メモリ 5,432 KB
最終ジャッジ日時 2023-09-22 21:18:26
合計ジャッジ時間 10,235 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 43 ms
5,432 KB
testcase_05 AC 43 ms
5,428 KB
testcase_06 AC 43 ms
5,428 KB
testcase_07 AC 43 ms
5,292 KB
testcase_08 AC 43 ms
5,304 KB
testcase_09 AC 43 ms
5,424 KB
testcase_10 AC 43 ms
5,428 KB
testcase_11 AC 43 ms
5,352 KB
testcase_12 AC 43 ms
5,400 KB
testcase_13 AC 43 ms
5,372 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 39 ms
4,816 KB
testcase_25 AC 52 ms
5,120 KB
testcase_26 AC 28 ms
4,380 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 50 ms
5,140 KB
testcase_29 AC 31 ms
4,376 KB
testcase_30 AC 51 ms
5,140 KB
testcase_31 AC 22 ms
4,376 KB
testcase_32 AC 18 ms
4,380 KB
testcase_33 AC 28 ms
4,384 KB
testcase_34 AC 29 ms
4,728 KB
testcase_35 AC 44 ms
5,156 KB
testcase_36 AC 27 ms
4,664 KB
testcase_37 AC 29 ms
4,384 KB
testcase_38 AC 41 ms
4,892 KB
testcase_39 AC 19 ms
4,376 KB
testcase_40 AC 23 ms
4,380 KB
testcase_41 AC 56 ms
5,156 KB
testcase_42 AC 28 ms
4,380 KB
testcase_43 AC 37 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N, Q;
    cin >> N >> Q;
    vector<pair<int, int>> dat;
    ll left_sum = 0, right_sum = 0, left_weight = 0, right_weight = 0;
    for(int i = 0; i < N; ++i){
        int x, w;
        cin >> x >> w;
        dat.emplace_back(x, w);
        right_sum += (ll)x * w;
        right_weight += w;
    }
    for(int i = 0; i < Q; ++i){
        int x;
        cin >> x;
        dat.emplace_back(x, -i);
    }
    sort(begin(dat), end(dat));
    vector<ll> ans(Q);
    for(auto [x, w] : dat){
        if(w > 0){
            left_sum += (ll)x * w; left_weight += w;
            right_sum -= (ll)x * w; right_weight -= w;
        }
        else{
            ans[-w] = (left_weight - right_weight) * x - left_sum + right_sum;
        }
    }
    for(int i = 0; i < Q; ++i)  cout << ans[i] << '\n';

    return 0;
}
0