結果

問題 No.1012 荷物収集
ユーザー i_mrhji_mrhj
提出日時 2020-03-22 12:03:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 97,500 KB
実行使用メモリ 7,380 KB
最終ジャッジ日時 2023-08-26 03:28:55
合計ジャッジ時間 12,758 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,572 KB
testcase_01 AC 3 ms
6,524 KB
testcase_02 AC 3 ms
6,520 KB
testcase_03 AC 3 ms
6,520 KB
testcase_04 AC 223 ms
7,228 KB
testcase_05 AC 218 ms
7,280 KB
testcase_06 AC 223 ms
7,268 KB
testcase_07 AC 221 ms
7,288 KB
testcase_08 AC 222 ms
7,280 KB
testcase_09 AC 224 ms
7,236 KB
testcase_10 AC 223 ms
7,324 KB
testcase_11 AC 221 ms
7,292 KB
testcase_12 AC 219 ms
7,276 KB
testcase_13 AC 223 ms
7,380 KB
testcase_14 AC 3 ms
6,600 KB
testcase_15 AC 4 ms
6,580 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 5 ms
6,732 KB
testcase_18 AC 4 ms
6,456 KB
testcase_19 AC 4 ms
6,800 KB
testcase_20 AC 3 ms
6,524 KB
testcase_21 AC 4 ms
6,508 KB
testcase_22 AC 4 ms
6,728 KB
testcase_23 AC 4 ms
6,464 KB
testcase_24 AC 177 ms
7,224 KB
testcase_25 AC 224 ms
7,284 KB
testcase_26 AC 91 ms
6,676 KB
testcase_27 AC 22 ms
6,484 KB
testcase_28 AC 202 ms
7,020 KB
testcase_29 AC 73 ms
6,780 KB
testcase_30 AC 207 ms
7,212 KB
testcase_31 AC 120 ms
7,100 KB
testcase_32 AC 78 ms
6,860 KB
testcase_33 AC 136 ms
7,044 KB
testcase_34 AC 161 ms
7,220 KB
testcase_35 AC 173 ms
6,908 KB
testcase_36 AC 151 ms
7,244 KB
testcase_37 AC 72 ms
6,596 KB
testcase_38 AC 178 ms
7,088 KB
testcase_39 AC 73 ms
6,908 KB
testcase_40 AC 95 ms
7,068 KB
testcase_41 AC 240 ms
7,128 KB
testcase_42 AC 119 ms
6,852 KB
testcase_43 AC 147 ms
7,140 KB
testcase_44 AC 3 ms
6,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

int main(void) {
  int n, q; cin >> n >> q;
  pair<ll, ll> x[100100]; rep(i, n) cin >> x[i].first >> x[i].second;
  ll y[100100]; rep(i, q) cin >> y[i];
  sort(x, x + n);
  ll s[100100] = {}, t[100100] = {};
  rep(i, n) {
    s[i + 1] = s[i] + x[i].second;
    t[i + 1] = t[i] + x[i].first * x[i].second;
  }
  rep(i, q) {
    int nk;
    if (y[i] < x[0].first) nk = 0;
    else {
      int le = 0, ri = n, med;
      while (ri - le > 1) {
	med = (ri + le) >> 1;
	if (x[med].first <= y[i]) le = med;
	else ri = med;
      }
      nk = le + 1;
    }
    cout << y[i]*s[nk]-t[nk]+(t[n]-t[nk])-y[i]*(s[n]-s[nk]) << endl;
  }
  return 0;
}
0