結果

問題 No.1012 荷物収集
ユーザー Y17Y17
提出日時 2020-03-20 22:04:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 175,688 KB
実行使用メモリ 8,464 KB
最終ジャッジ日時 2024-05-08 22:08:41
合計ジャッジ時間 9,534 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 3 ms
5,760 KB
testcase_02 AC 4 ms
5,888 KB
testcase_03 AC 3 ms
5,632 KB
testcase_04 AC 237 ms
8,332 KB
testcase_05 AC 235 ms
8,224 KB
testcase_06 AC 236 ms
8,204 KB
testcase_07 AC 230 ms
8,204 KB
testcase_08 AC 232 ms
8,332 KB
testcase_09 AC 228 ms
8,460 KB
testcase_10 AC 223 ms
8,244 KB
testcase_11 AC 227 ms
8,332 KB
testcase_12 AC 226 ms
8,232 KB
testcase_13 AC 229 ms
8,464 KB
testcase_14 AC 3 ms
5,888 KB
testcase_15 AC 4 ms
5,888 KB
testcase_16 AC 4 ms
5,760 KB
testcase_17 AC 5 ms
5,760 KB
testcase_18 AC 5 ms
5,760 KB
testcase_19 AC 3 ms
5,760 KB
testcase_20 AC 3 ms
5,632 KB
testcase_21 AC 4 ms
5,888 KB
testcase_22 AC 5 ms
5,760 KB
testcase_23 AC 4 ms
5,760 KB
testcase_24 AC 177 ms
7,040 KB
testcase_25 AC 211 ms
8,040 KB
testcase_26 AC 92 ms
7,752 KB
testcase_27 AC 22 ms
6,144 KB
testcase_28 AC 204 ms
8,164 KB
testcase_29 AC 75 ms
8,296 KB
testcase_30 AC 197 ms
8,324 KB
testcase_31 AC 123 ms
5,760 KB
testcase_32 AC 80 ms
6,144 KB
testcase_33 AC 133 ms
6,272 KB
testcase_34 AC 161 ms
6,016 KB
testcase_35 AC 167 ms
7,888 KB
testcase_36 AC 149 ms
6,144 KB
testcase_37 AC 74 ms
8,048 KB
testcase_38 AC 175 ms
7,168 KB
testcase_39 AC 73 ms
6,784 KB
testcase_40 AC 93 ms
6,400 KB
testcase_41 AC 231 ms
8,136 KB
testcase_42 AC 120 ms
6,784 KB
testcase_43 AC 148 ms
7,828 KB
testcase_44 AC 3 ms
5,760 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