結果

問題 No.1012 荷物収集
ユーザー どららどらら
提出日時 2020-03-20 22:03:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 172,976 KB
実行使用メモリ 10,852 KB
最終ジャッジ日時 2023-08-21 16:40:43
合計ジャッジ時間 10,583 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 234 ms
10,020 KB
testcase_05 AC 230 ms
10,304 KB
testcase_06 AC 233 ms
9,596 KB
testcase_07 AC 235 ms
10,244 KB
testcase_08 AC 233 ms
10,364 KB
testcase_09 AC 232 ms
9,780 KB
testcase_10 AC 235 ms
10,020 KB
testcase_11 AC 231 ms
10,744 KB
testcase_12 AC 233 ms
9,912 KB
testcase_13 AC 233 ms
10,252 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,388 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 3 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 173 ms
6,348 KB
testcase_25 AC 215 ms
9,892 KB
testcase_26 AC 89 ms
6,444 KB
testcase_27 AC 21 ms
4,380 KB
testcase_28 AC 198 ms
9,284 KB
testcase_29 AC 77 ms
6,152 KB
testcase_30 AC 196 ms
10,852 KB
testcase_31 AC 125 ms
6,256 KB
testcase_32 AC 78 ms
4,732 KB
testcase_33 AC 140 ms
7,016 KB
testcase_34 AC 158 ms
6,488 KB
testcase_35 AC 165 ms
9,544 KB
testcase_36 AC 155 ms
6,152 KB
testcase_37 AC 74 ms
6,148 KB
testcase_38 AC 173 ms
6,744 KB
testcase_39 AC 72 ms
4,672 KB
testcase_40 AC 95 ms
6,100 KB
testcase_41 AC 224 ms
10,316 KB
testcase_42 AC 121 ms
6,264 KB
testcase_43 AC 143 ms
6,496 KB
testcase_44 AC 2 ms
4,380 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