結果

問題 No.1012 荷物収集
ユーザー furafura
提出日時 2020-07-25 15:31:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 211,816 KB
実行使用メモリ 13,076 KB
最終ジャッジ日時 2023-09-09 13:48:54
合計ジャッジ時間 11,213 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 75 ms
12,816 KB
testcase_05 AC 74 ms
12,872 KB
testcase_06 AC 75 ms
12,744 KB
testcase_07 AC 75 ms
12,756 KB
testcase_08 AC 74 ms
13,048 KB
testcase_09 AC 75 ms
13,076 KB
testcase_10 AC 75 ms
12,748 KB
testcase_11 AC 75 ms
12,824 KB
testcase_12 AC 76 ms
12,916 KB
testcase_13 AC 75 ms
12,872 KB
testcase_14 AC 2 ms
4,388 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,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 64 ms
8,584 KB
testcase_25 AC 93 ms
11,084 KB
testcase_26 AC 64 ms
9,204 KB
testcase_27 AC 14 ms
4,724 KB
testcase_28 AC 96 ms
11,772 KB
testcase_29 AC 75 ms
10,752 KB
testcase_30 AC 103 ms
12,036 KB
testcase_31 AC 26 ms
4,732 KB
testcase_32 AC 28 ms
5,432 KB
testcase_33 AC 38 ms
5,952 KB
testcase_34 AC 39 ms
5,784 KB
testcase_35 AC 84 ms
10,372 KB
testcase_36 AC 34 ms
4,992 KB
testcase_37 AC 72 ms
10,168 KB
testcase_38 AC 71 ms
9,252 KB
testcase_39 AC 35 ms
6,288 KB
testcase_40 AC 37 ms
6,340 KB
testcase_41 AC 108 ms
12,220 KB
testcase_42 AC 45 ms
7,124 KB
testcase_43 AC 72 ms
9,504 KB
testcase_44 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n,q; scanf("%d%d",&n,&q);
	vector<lint> x(n),w(n);
	rep(i,n) scanf("%lld%lld",&x[i],&w[i]);
	vector<lint> a(q);
	rep(i,q) scanf("%lld",&a[i]);

	vector<int> p(q);
	iota(p.begin(),p.end(),0);
	sort(p.begin(),p.end(),[&](int i,int j){ return a[i]<a[j]; });

	lint cost_L=0,cost_R=0,wsum_L=0,wsum_R=0;
	set<pair<lint,lint>> L,R;
	rep(i,n){
		R.emplace(x[i],w[i]);
		cost_R+=w[i]*x[i];
		wsum_R+=w[i];
	}
	vector<lint> ans(q);
	for(int i:p){
		while(!R.empty() && R.begin()->first<a[i]){
			auto [x0,w0]=*R.begin();
			R.erase(R.begin());
			cost_R-=w0*x0;
			wsum_R-=w0;
			L.emplace(x0,w0);
			cost_L+=w0*x0;
			wsum_L+=w0;
		}
		ans[i]=(cost_R-wsum_R*a[i])+(wsum_L*a[i]-cost_L);
	}

	rep(i,q) printf("%lld\n",ans[i]);

	return 0;
}
0