結果

問題 No.1012 荷物収集
ユーザー どららどらら
提出日時 2020-03-20 22:03:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 174,556 KB
実行使用メモリ 9,556 KB
最終ジャッジ日時 2024-05-08 22:06:59
合計ジャッジ時間 9,381 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 228 ms
9,552 KB
testcase_05 AC 218 ms
9,552 KB
testcase_06 AC 221 ms
9,556 KB
testcase_07 AC 216 ms
9,552 KB
testcase_08 AC 222 ms
9,552 KB
testcase_09 AC 219 ms
9,552 KB
testcase_10 AC 225 ms
9,504 KB
testcase_11 AC 227 ms
9,552 KB
testcase_12 AC 215 ms
9,556 KB
testcase_13 AC 216 ms
9,552 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 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 3 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 160 ms
6,860 KB
testcase_25 AC 203 ms
9,552 KB
testcase_26 AC 86 ms
6,480 KB
testcase_27 AC 21 ms
5,376 KB
testcase_28 AC 195 ms
9,552 KB
testcase_29 AC 76 ms
6,480 KB
testcase_30 AC 193 ms
9,552 KB
testcase_31 AC 118 ms
6,480 KB
testcase_32 AC 77 ms
5,376 KB
testcase_33 AC 130 ms
6,480 KB
testcase_34 AC 156 ms
6,552 KB
testcase_35 AC 165 ms
9,552 KB
testcase_36 AC 152 ms
6,604 KB
testcase_37 AC 77 ms
6,480 KB
testcase_38 AC 168 ms
6,872 KB
testcase_39 AC 68 ms
5,376 KB
testcase_40 AC 88 ms
6,480 KB
testcase_41 AC 214 ms
9,552 KB
testcase_42 AC 112 ms
6,480 KB
testcase_43 AC 141 ms
6,480 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int t;
  ll x, w;
};
bool operator<(const ST& a ,const ST& b){
  return a.x < b.x;
}

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<ST> v;
  rep(i,N){
    ST st;
    st.t = -1;
    cin >> st.x >> st.w;
    v.push_back(st);
  }
  rep(i,Q){
    ST st;
    st.t = i;
    st.w = 0;
    cin >> st.x;
    v.push_back(st);
  }
  sort(ALLOF(v));

  vector<ll> ret(Q, 0);
  {
    ll base = 0;
    ll prev_sum = 0;
    ll prev_x = v[0].x;
    rep(i,v.size()){
      if(v[i].t >= 0){
        ret[v[i].t] += prev_sum + (v[i].x - prev_x) * base;
      }
      prev_sum += (v[i].x - prev_x) * base;
      prev_x = v[i].x;
      base += v[i].w;
    }
  }
  {
    ll base = 0;
    ll prev_sum = 0;
    ll prev_x = v[v.size()-1].x;

    for(int i=v.size()-1; i>=0; i--){
      if(v[i].t >= 0){
        ret[v[i].t] += prev_sum + (prev_x - v[i].x) * base;
      }
      prev_sum += (prev_x - v[i].x) * base;
      prev_x = v[i].x;
      base += v[i].w;
    }
  }

  rep(i,ret.size()){
    cout << ret[i] << endl;
  }
  
  return 0;
}

0