結果

問題 No.1012 荷物収集
ユーザー tnakao0123tnakao0123
提出日時 2020-03-21 04:04:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,155 bytes
コンパイル時間 916 ms
コンパイル使用メモリ 98,896 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-09 17:42:45
合計ジャッジ時間 6,586 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 50 ms
6,940 KB
testcase_05 AC 51 ms
6,944 KB
testcase_06 AC 50 ms
6,940 KB
testcase_07 AC 50 ms
6,940 KB
testcase_08 AC 49 ms
6,944 KB
testcase_09 AC 49 ms
6,944 KB
testcase_10 AC 49 ms
6,944 KB
testcase_11 AC 48 ms
6,940 KB
testcase_12 AC 48 ms
6,940 KB
testcase_13 AC 50 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 44 ms
6,944 KB
testcase_25 AC 57 ms
6,940 KB
testcase_26 AC 30 ms
5,376 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 58 ms
5,760 KB
testcase_29 AC 32 ms
6,144 KB
testcase_30 AC 58 ms
6,016 KB
testcase_31 AC 23 ms
5,376 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 30 ms
5,376 KB
testcase_34 AC 35 ms
5,376 KB
testcase_35 AC 48 ms
5,632 KB
testcase_36 AC 30 ms
5,376 KB
testcase_37 AC 29 ms
5,760 KB
testcase_38 AC 48 ms
5,376 KB
testcase_39 AC 21 ms
5,376 KB
testcase_40 AC 25 ms
5,376 KB
testcase_41 AC 65 ms
6,016 KB
testcase_42 AC 30 ms
5,376 KB
testcase_43 AC 43 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1012.cc:  No.1012 荷物収集 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;

/* global variables */

pii ps[MAX_N];
ll xwss[MAX_N + 1], wss[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, q;
  scanf("%d%d", &n, &q);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &ps[i].first, &ps[i].second);
  sort(ps, ps + n);

  for (int i = 0; i < n; i++) {
    xwss[i + 1] = xwss[i] + (ll)ps[i].first * ps[i].second;
    wss[i + 1] = wss[i] + ps[i].second;
  }

  while (q--) {
    int xq;
    scanf("%d", &xq);

    int k = lower_bound(ps, ps + n, pii(xq, 0)) - ps;

    ll sum =
      (xwss[n] - xwss[k] - (wss[n] - wss[k]) * xq) + (wss[k] * xq - xwss[k]);
    printf("%lld\n", sum);
  }
  return 0;
}
0