結果

問題 No.1012 荷物収集
ユーザー micheeeeell1001micheeeeell1001
提出日時 2020-03-20 22:20:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,510 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 177,188 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-05-08 22:33:03
合計ジャッジ時間 7,779 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 116 ms
8,704 KB
testcase_05 AC 115 ms
8,704 KB
testcase_06 AC 116 ms
8,832 KB
testcase_07 AC 116 ms
8,704 KB
testcase_08 AC 115 ms
8,704 KB
testcase_09 AC 115 ms
8,704 KB
testcase_10 AC 119 ms
8,704 KB
testcase_11 AC 115 ms
8,704 KB
testcase_12 AC 115 ms
8,704 KB
testcase_13 AC 115 ms
8,832 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
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 89 ms
6,272 KB
testcase_25 AC 120 ms
7,680 KB
testcase_26 AC 70 ms
6,656 KB
testcase_27 AC 17 ms
5,376 KB
testcase_28 AC 120 ms
7,936 KB
testcase_29 AC 77 ms
7,808 KB
testcase_30 AC 123 ms
8,448 KB
testcase_31 AC 42 ms
5,376 KB
testcase_32 AC 39 ms
5,376 KB
testcase_33 AC 58 ms
5,376 KB
testcase_34 AC 62 ms
5,376 KB
testcase_35 AC 101 ms
7,424 KB
testcase_36 AC 55 ms
5,376 KB
testcase_37 AC 73 ms
7,424 KB
testcase_38 AC 95 ms
6,656 KB
testcase_39 AC 45 ms
5,376 KB
testcase_40 AC 51 ms
5,376 KB
testcase_41 AC 133 ms
8,320 KB
testcase_42 AC 62 ms
5,376 KB
testcase_43 AC 89 ms
6,784 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,q; cin >> n >> q;
    vector<ll> a(n),b(n);
    vector<Pll> ab(n);
    rep(i,n){
        ll a,b; cin >> a >> b;
        ab[i] = {a,b};
    }
    sort(all(ab));
    rep(i,n){
        a[i] = ab[i].first;
        b[i] = ab[i].second;
    }
    // rep(i,n)cin >> a[i] >> b[i];
    vector<ll> sum_ab(n+1), sum_b(n+1);
    rep(i,n){
        sum_ab[i+1] = sum_ab[i] + a[i] * b[i];
        sum_b[i+1] = sum_b[i] + b[i];
    }
    vector<ll> x(q);
    rep(i,q) cin >> x[i];
    rep(i,q){
        ll id = lower_bound(all(a), x[i]) - a.begin();
        // debug(id);
        ll ans = 0;
        ans -= sum_ab[id] - sum_ab[0];
        ans += sum_ab[n] - sum_ab[id];
        ans += x[i] * (sum_b[id] - sum_b[0]);
        ans -= x[i] * (sum_b[n] - sum_b[id]);
        cout << ans << "\n";
    }
}
0