結果

問題 No.1012 荷物収集
ユーザー snrnsidysnrnsidy
提出日時 2021-09-02 11:52:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 2,377 ms
コンパイル使用メモリ 210,336 KB
実行使用メモリ 7,348 KB
最終ジャッジ日時 2023-08-19 21:44:59
合計ジャッジ時間 10,435 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 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 48 ms
6,492 KB
testcase_05 AC 47 ms
6,436 KB
testcase_06 AC 46 ms
6,456 KB
testcase_07 AC 46 ms
7,252 KB
testcase_08 AC 46 ms
6,604 KB
testcase_09 AC 46 ms
6,460 KB
testcase_10 AC 47 ms
6,376 KB
testcase_11 AC 46 ms
6,444 KB
testcase_12 AC 47 ms
6,388 KB
testcase_13 AC 46 ms
6,944 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 41 ms
5,140 KB
testcase_25 AC 54 ms
7,208 KB
testcase_26 AC 30 ms
4,756 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 54 ms
6,136 KB
testcase_29 AC 32 ms
4,720 KB
testcase_30 AC 55 ms
6,212 KB
testcase_31 AC 24 ms
4,776 KB
testcase_32 AC 18 ms
4,380 KB
testcase_33 AC 29 ms
4,696 KB
testcase_34 AC 32 ms
4,932 KB
testcase_35 AC 45 ms
6,388 KB
testcase_36 AC 29 ms
4,816 KB
testcase_37 AC 30 ms
4,808 KB
testcase_38 AC 44 ms
5,088 KB
testcase_39 AC 21 ms
4,380 KB
testcase_40 AC 23 ms
4,700 KB
testcase_41 AC 60 ms
7,348 KB
testcase_42 AC 30 ms
4,712 KB
testcase_43 AC 40 ms
4,800 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

long long int res[100005];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, q, x, w, t;
	vector <pair<pair<int, int>, int>> v;

	cin >> n >> q;

	for (int i = 0; i < n; i++)
	{
		cin >> x >> w;
		v.push_back(make_pair(make_pair(x, 1), w));
	}

	for (int i = 0; i < q; i++)
	{
		cin >> t;
		v.push_back(make_pair(make_pair(t, 0), i));
	}

	sort(v.begin(), v.end());

	long long int sum = 0;
	long long int X = v[0].first.first;
	long long int val = 0;

	for (int i = 0; i < v.size(); i++)
	{
		long long int x = v[i].first.first;
		int sel = v[i].first.second;
		val += ((x - X) * sum);
		X = x;
		if (sel == 0)
		{
			int idx = v[i].second;
			res[idx] += val;
		}
		else
		{
			sum += v[i].second;
		}
		v[i].first.second = 1 - v[i].first.second;
	}

	sort(v.rbegin(), v.rend());

	sum = 0;
	X = v[0].first.first;
	val = 0;

	for (int i = 0; i < v.size(); i++)
	{
		long long int x = v[i].first.first;
		int sel = v[i].first.second;
		val += ((X - x) * sum);
		X = x;
		if (sel == 1)
		{
			int idx = v[i].second;
			res[idx] += val;
		}
		else
		{
			sum += v[i].second;
		}
		v[i].first.second = 1 - v[i].first.second;
	}

	for (int i = 0; i < q; i++)
	{
		cout << res[i] << '\n';
	}
	return 0;
}
0