結果

問題 No.1012 荷物収集
ユーザー leaf_1415leaf_1415
提出日時 2020-03-20 21:56:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 7,900 KB
最終ジャッジ日時 2023-08-21 16:24:01
合計ジャッジ時間 8,649 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 170 ms
7,656 KB
testcase_05 AC 182 ms
7,740 KB
testcase_06 AC 174 ms
7,664 KB
testcase_07 AC 175 ms
7,900 KB
testcase_08 AC 172 ms
7,660 KB
testcase_09 AC 173 ms
7,860 KB
testcase_10 AC 175 ms
7,844 KB
testcase_11 AC 174 ms
7,800 KB
testcase_12 AC 175 ms
7,800 KB
testcase_13 AC 173 ms
7,808 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 143 ms
5,860 KB
testcase_25 AC 171 ms
7,012 KB
testcase_26 AC 62 ms
6,484 KB
testcase_27 AC 14 ms
4,380 KB
testcase_28 AC 155 ms
7,396 KB
testcase_29 AC 39 ms
7,792 KB
testcase_30 AC 152 ms
7,856 KB
testcase_31 AC 107 ms
4,376 KB
testcase_32 AC 64 ms
4,376 KB
testcase_33 AC 116 ms
4,376 KB
testcase_34 AC 133 ms
4,376 KB
testcase_35 AC 130 ms
6,944 KB
testcase_36 AC 135 ms
4,376 KB
testcase_37 AC 40 ms
7,536 KB
testcase_38 AC 142 ms
5,904 KB
testcase_39 AC 55 ms
4,936 KB
testcase_40 AC 76 ms
4,680 KB
testcase_41 AC 182 ms
7,716 KB
testcase_42 AC 96 ms
4,844 KB
testcase_43 AC 111 ms
6,340 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)

using namespace std;
typedef pair<llint, llint> P;

llint n, Q;
llint x[100005], w[100005];
vector<P> vec;
llint s[100005];
llint sum[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> Q;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> w[i];
		vec.push_back(P(x[i], w[i]));
	}
	sort(vec.begin(), vec.end());
	
	for(int i = 0; i < vec.size(); i++){
		s[i+1] = s[i] + vec[i].second;
		sum[i+1] = sum[i] + vec[i].first*vec[i].second;
	}
	
	llint y;
	for(int q = 0; q < Q; q++){
		cin >> y;
		llint p = lower_bound(vec.begin(), vec.end(), P(y, -inf)) - vec.begin();
		llint rnum = n - p, lnum = p;
		llint lsum = y*s[lnum] - sum[lnum], rsum = sum[n]-sum[lnum] - y*(s[n]-s[lnum]);
		cout << lsum + rsum << endl;
	}
	
	return 0;
}
0