結果

問題 No.1012 荷物収集
ユーザー kawara_y_kyoprokawara_y_kyopro
提出日時 2020-03-20 22:38:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,257 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 113,544 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-05-08 23:11:27
合計ジャッジ時間 5,512 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 45 ms
7,936 KB
testcase_05 AC 46 ms
7,808 KB
testcase_06 AC 45 ms
7,936 KB
testcase_07 AC 45 ms
7,936 KB
testcase_08 AC 45 ms
7,936 KB
testcase_09 AC 45 ms
7,808 KB
testcase_10 AC 45 ms
7,936 KB
testcase_11 AC 45 ms
7,808 KB
testcase_12 AC 46 ms
8,064 KB
testcase_13 AC 45 ms
8,064 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 44 ms
5,760 KB
testcase_25 AC 59 ms
7,040 KB
testcase_26 AC 32 ms
6,528 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 57 ms
7,296 KB
testcase_29 AC 33 ms
7,680 KB
testcase_30 AC 58 ms
7,936 KB
testcase_31 AC 21 ms
5,376 KB
testcase_32 AC 19 ms
5,376 KB
testcase_33 AC 29 ms
5,376 KB
testcase_34 WA -
testcase_35 AC 48 ms
7,040 KB
testcase_36 AC 27 ms
5,376 KB
testcase_37 AC 31 ms
7,424 KB
testcase_38 AC 46 ms
6,144 KB
testcase_39 AC 21 ms
5,376 KB
testcase_40 AC 25 ms
5,376 KB
testcase_41 AC 65 ms
7,552 KB
testcase_42 AC 30 ms
5,376 KB
testcase_43 AC 41 ms
6,400 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

constexpr long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q; cin >> n >> q;
    V< P<ll, ll> > xw(n);
    for (ll i = 0; i < n; i++) cin >> xw[i].first >> xw[i].second;
    sort(ALL(xw));
    vll lwacc(n + 1, 0), rwacc(n + 1, 0);
    vll lcost(n, 0), rcost(n, 0);
    for (ll i = 0; i < n; i++) {
        lwacc[i + 1] = lwacc[i] + xw[i].second;
    }
    for (ll i = n - 1; i >= 0; i--) {
        rwacc[i] = rwacc[i + 1] + xw[i].second;
    }
    for (ll i = 1; i < n; i++) {
        lcost[i] = lcost[i - 1] + lwacc[i] * (xw[i].first - xw[i - 1].first);
    }
    for (ll i = n - 2; i >= 0; i--) {
        rcost[i] = rcost[i + 1] + rwacc[i + 1] * (xw[i + 1].first - xw[i].first);
    }

    while (q-->0) {
        ll x; cin >> x;
        ll idx = lower_bound(ALL(xw), make_pair(x, 0LL)) - xw.begin();
        if (xw[idx].first == x) {
            cout << lcost[idx] + rcost[idx] << '\n';
        } else {
            ll cost = lcost[max(0LL, idx - 1)] + rcost[idx] + (x - xw[max(0LL, idx - 1)].first) * lwacc[idx] + abs(xw[min(idx, n)].first - x) * rwacc[idx];
            cout << cost << '\n';
        }
    }
    return 0;
}
0