結果

問題 No.1012 荷物収集
ユーザー polylogKpolylogK
提出日時 2020-03-20 21:43:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 173,256 KB
実行使用メモリ 8,036 KB
最終ジャッジ日時 2023-08-21 15:58:23
合計ジャッジ時間 7,018 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 54 ms
8,008 KB
testcase_05 AC 54 ms
7,936 KB
testcase_06 AC 54 ms
7,952 KB
testcase_07 AC 54 ms
8,000 KB
testcase_08 AC 55 ms
8,004 KB
testcase_09 AC 53 ms
7,992 KB
testcase_10 AC 54 ms
8,036 KB
testcase_11 AC 53 ms
7,948 KB
testcase_12 AC 54 ms
7,900 KB
testcase_13 AC 54 ms
8,000 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 45 ms
6,064 KB
testcase_25 AC 59 ms
7,016 KB
testcase_26 AC 32 ms
5,352 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 57 ms
7,296 KB
testcase_29 AC 34 ms
5,588 KB
testcase_30 AC 59 ms
7,428 KB
testcase_31 AC 26 ms
4,700 KB
testcase_32 AC 20 ms
4,564 KB
testcase_33 AC 32 ms
5,428 KB
testcase_34 AC 34 ms
5,484 KB
testcase_35 AC 49 ms
6,380 KB
testcase_36 AC 33 ms
5,156 KB
testcase_37 AC 33 ms
5,472 KB
testcase_38 AC 47 ms
6,304 KB
testcase_39 AC 21 ms
4,600 KB
testcase_40 AC 26 ms
4,768 KB
testcase_41 AC 64 ms
7,560 KB
testcase_42 AC 31 ms
5,108 KB
testcase_43 AC 43 ms
6,000 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, q; scanf("%d%d", &n, &q);
	std::vector<i64> a(n), b(n), c(q);
	for(int i = 0; i < n; i++) scanf("%lld%lld", &a[i], &b[i]);
	for(int i = 0; i < q; i++) scanf("%lld", &c[i]);
	
	std::vector<std::pair<int, int>> A, B;
	for(int i = 0; i < n; i++) A.push_back({a[i], i});
	for(int i = 0; i < q; i++) B.push_back({c[i], i});
	sort(begin(A), end(A)); sort(begin(B), end(B));

	int cnt = 0;
	i64 now = 0, L = 0, R = std::accumulate(begin(b), end(b), 0LL), last = 0;
	for(int i = 0; i < n; i++) now += a[i] * b[i];
	
	std::vector<i64> ans(q);
	for(int i = 0; i < B.size(); i++) {
		int x = B[i].first;
		while(cnt < A.size() and A[cnt].first <= x) {
			int id = A[cnt++].second;
			i64 len = a[id] - last;
			now += len * L;
			now -= len * R;
			last = a[id];
			L += b[id];
			R -= b[id];
		}
		i64 len = x - last;
		now += len * L;
		now -= len * R;
		last = x;

		ans[B[i].second] = now;
	}

	for(auto v: ans) printf("%lld\n", v);
	return 0;
}
0