結果

問題 No.1012 荷物収集
ユーザー Plan8Plan8
提出日時 2020-03-20 22:41:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 2,099 bytes
コンパイル時間 2,626 ms
コンパイル使用メモリ 172,476 KB
実行使用メモリ 6,372 KB
最終ジャッジ日時 2023-08-21 17:44:53
合計ジャッジ時間 11,129 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 242 ms
6,240 KB
testcase_05 AC 237 ms
6,164 KB
testcase_06 AC 237 ms
6,164 KB
testcase_07 AC 238 ms
6,232 KB
testcase_08 AC 244 ms
6,372 KB
testcase_09 AC 240 ms
6,296 KB
testcase_10 AC 239 ms
6,236 KB
testcase_11 AC 236 ms
6,180 KB
testcase_12 AC 238 ms
6,232 KB
testcase_13 AC 239 ms
6,296 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 177 ms
4,660 KB
testcase_25 AC 224 ms
5,700 KB
testcase_26 AC 91 ms
5,160 KB
testcase_27 AC 21 ms
4,380 KB
testcase_28 AC 205 ms
5,924 KB
testcase_29 AC 75 ms
5,924 KB
testcase_30 AC 210 ms
6,180 KB
testcase_31 AC 122 ms
4,380 KB
testcase_32 AC 80 ms
4,376 KB
testcase_33 AC 138 ms
4,376 KB
testcase_34 AC 153 ms
4,376 KB
testcase_35 AC 178 ms
5,440 KB
testcase_36 AC 157 ms
4,380 KB
testcase_37 AC 75 ms
6,096 KB
testcase_38 AC 186 ms
4,972 KB
testcase_39 AC 72 ms
4,380 KB
testcase_40 AC 97 ms
4,380 KB
testcase_41 AC 249 ms
6,100 KB
testcase_42 AC 122 ms
4,448 KB
testcase_43 AC 149 ms
5,236 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    ll N,Q; cin >> N >> Q;
    vector<pair<ll,ll>> v(N); REP(i,N) cin >> v[i].first >> v[i].second;
    SORT(v);

    vector<ll> xw(N+1), w(N+1);
    xw[0] = 0;
    REP(i,N) xw[i+1] = xw[i] + v[i].first*v[i].second;
    w[0] = 0;
    REP(i,N) w[i+1] = w[i] + v[i].second;

    auto lb = [&](ll val){
        ll l = -1, r = N, n = (l+r)/2;
        while(r-l>1){
            if(v[n].first < val) l = n;
            else r = n;
            n = (l+r)/2;
        }
        return r;
    };

    REP(i,Q){
        ll X; cin >> X;
        ll it = lb(X);
        ll L = xw[it] - X*w[it];
        ll R = (xw[N]-xw[it]) - X*(w[N]-w[it]);
        cout << R-L << en;
    }
    return 0;
}
0