結果

問題 No.1012 荷物収集
ユーザー i_mrhj
提出日時 2020-03-22 12:03:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 99,348 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-12-24 17:01:28
合計ジャッジ時間 10,680 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

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