結果

問題 No.1012 荷物収集
ユーザー i_mrhji_mrhj
提出日時 2020-03-22 12:03:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 100,572 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-06-06 22:25:13
合計ジャッジ時間 9,423 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,656 KB
testcase_01 AC 2 ms
6,784 KB
testcase_02 AC 3 ms
6,656 KB
testcase_03 AC 2 ms
6,656 KB
testcase_04 AC 194 ms
7,248 KB
testcase_05 AC 198 ms
7,248 KB
testcase_06 AC 203 ms
7,424 KB
testcase_07 AC 202 ms
7,296 KB
testcase_08 AC 205 ms
7,368 KB
testcase_09 AC 220 ms
7,244 KB
testcase_10 AC 212 ms
7,372 KB
testcase_11 AC 199 ms
7,296 KB
testcase_12 AC 209 ms
7,296 KB
testcase_13 AC 207 ms
7,296 KB
testcase_14 AC 3 ms
6,656 KB
testcase_15 AC 4 ms
6,784 KB
testcase_16 AC 3 ms
6,528 KB
testcase_17 AC 4 ms
6,656 KB
testcase_18 AC 4 ms
6,656 KB
testcase_19 AC 3 ms
6,656 KB
testcase_20 AC 3 ms
6,784 KB
testcase_21 AC 4 ms
6,656 KB
testcase_22 AC 4 ms
6,784 KB
testcase_23 AC 3 ms
6,656 KB
testcase_24 AC 155 ms
7,124 KB
testcase_25 AC 187 ms
7,116 KB
testcase_26 AC 79 ms
6,784 KB
testcase_27 AC 19 ms
6,784 KB
testcase_28 AC 180 ms
7,168 KB
testcase_29 AC 69 ms
6,784 KB
testcase_30 AC 183 ms
6,992 KB
testcase_31 AC 106 ms
7,124 KB
testcase_32 AC 68 ms
6,944 KB
testcase_33 AC 119 ms
7,120 KB
testcase_34 AC 135 ms
7,244 KB
testcase_35 AC 154 ms
7,040 KB
testcase_36 AC 139 ms
7,168 KB
testcase_37 AC 65 ms
6,784 KB
testcase_38 AC 159 ms
6,988 KB
testcase_39 AC 67 ms
6,784 KB
testcase_40 AC 87 ms
6,912 KB
testcase_41 AC 205 ms
7,120 KB
testcase_42 AC 102 ms
6,940 KB
testcase_43 AC 127 ms
6,992 KB
testcase_44 AC 2 ms
6,784 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