結果

問題 No.1012 荷物収集
ユーザー Y17Y17
提出日時 2020-03-20 22:04:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 174,132 KB
実行使用メモリ 8,056 KB
最終ジャッジ日時 2023-08-21 16:43:07
合計ジャッジ時間 10,898 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,764 KB
testcase_01 AC 3 ms
5,760 KB
testcase_02 AC 2 ms
5,688 KB
testcase_03 AC 3 ms
5,672 KB
testcase_04 AC 232 ms
8,056 KB
testcase_05 AC 229 ms
7,940 KB
testcase_06 AC 229 ms
7,940 KB
testcase_07 AC 230 ms
7,944 KB
testcase_08 AC 230 ms
8,008 KB
testcase_09 AC 229 ms
8,008 KB
testcase_10 AC 229 ms
8,044 KB
testcase_11 AC 232 ms
7,908 KB
testcase_12 AC 231 ms
7,936 KB
testcase_13 AC 235 ms
7,976 KB
testcase_14 AC 4 ms
5,692 KB
testcase_15 AC 5 ms
5,708 KB
testcase_16 AC 4 ms
5,692 KB
testcase_17 AC 4 ms
5,696 KB
testcase_18 AC 5 ms
5,764 KB
testcase_19 AC 4 ms
5,680 KB
testcase_20 AC 3 ms
5,704 KB
testcase_21 AC 4 ms
5,764 KB
testcase_22 AC 5 ms
5,680 KB
testcase_23 AC 4 ms
5,700 KB
testcase_24 AC 180 ms
6,872 KB
testcase_25 AC 225 ms
7,896 KB
testcase_26 AC 94 ms
7,488 KB
testcase_27 AC 22 ms
6,036 KB
testcase_28 AC 207 ms
7,740 KB
testcase_29 AC 78 ms
7,912 KB
testcase_30 AC 206 ms
7,960 KB
testcase_31 AC 122 ms
5,760 KB
testcase_32 AC 83 ms
6,180 KB
testcase_33 AC 144 ms
6,068 KB
testcase_34 AC 162 ms
5,844 KB
testcase_35 AC 175 ms
7,576 KB
testcase_36 AC 156 ms
5,932 KB
testcase_37 AC 75 ms
7,772 KB
testcase_38 AC 180 ms
6,928 KB
testcase_39 AC 74 ms
6,504 KB
testcase_40 AC 97 ms
6,512 KB
testcase_41 AC 239 ms
7,972 KB
testcase_42 AC 120 ms
6,708 KB
testcase_43 AC 150 ms
7,436 KB
testcase_44 AC 3 ms
5,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int n, q;
	cin >> n >> q;

	vector<pair<int, int>> x(n);
	for(int i = 0;i < n;i++){
		cin >> x[i].first >> x[i].second;
	}
	sort(x.begin(), x.end());

	int sx[100010] = {};
	int rui[100010] = {};
	int rx[100010] = {};
	int r;
	sx[1] = 0;
	r = x[0].second;
	for(int i = 1;i < n;i++){
		sx[i+1] = sx[i] + r*(x[i].first-x[i-1].first);
		r += x[i].second;
	}

	rx[n-1] = 0;
	r = x[n-1].second;
	for(int i = n-2;i >= 0;i--){
		rx[i] = rx[i+1] + r*(x[i+1].first-x[i].first);
		r += x[i].second;
	} 

	vector<int> vec;
	for(int i = 0;i < n;i++){
		vec.push_back(x[i].first);
		rui[i+1] = rui[i] + x[i].second;
	}

	for(int i = 0;i < q;i++){
		int X;
		cin >> X;
		int idx = upper_bound(vec.begin(), vec.end(), X) - vec.begin();
		cout << sx[idx] + rx[idx] + rui[idx] * (X-x[idx-1].first) + (rui[n]-rui[idx]) * (x[idx].first - X) << endl;
	}
	return 0;
}
0