結果

問題 No.1012 荷物収集
ユーザー 沙耶花沙耶花
提出日時 2020-03-20 21:50:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 3,226 ms
コンパイル使用メモリ 208,176 KB
実行使用メモリ 7,896 KB
最終ジャッジ日時 2023-08-21 16:12:23
合計ジャッジ時間 11,453 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 182 ms
6,836 KB
testcase_05 AC 188 ms
7,896 KB
testcase_06 AC 187 ms
6,900 KB
testcase_07 AC 181 ms
7,120 KB
testcase_08 AC 185 ms
6,804 KB
testcase_09 AC 186 ms
6,996 KB
testcase_10 AC 180 ms
6,940 KB
testcase_11 AC 184 ms
7,152 KB
testcase_12 AC 182 ms
6,964 KB
testcase_13 AC 184 ms
6,940 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 148 ms
5,184 KB
testcase_25 AC 180 ms
6,412 KB
testcase_26 AC 61 ms
5,888 KB
testcase_27 AC 14 ms
4,380 KB
testcase_28 AC 162 ms
6,568 KB
testcase_29 AC 38 ms
6,952 KB
testcase_30 AC 160 ms
6,832 KB
testcase_31 AC 107 ms
4,376 KB
testcase_32 AC 64 ms
4,500 KB
testcase_33 AC 119 ms
4,376 KB
testcase_34 AC 138 ms
4,380 KB
testcase_35 AC 132 ms
6,332 KB
testcase_36 AC 143 ms
4,380 KB
testcase_37 AC 40 ms
6,868 KB
testcase_38 AC 150 ms
5,556 KB
testcase_39 AC 56 ms
4,624 KB
testcase_40 AC 79 ms
4,500 KB
testcase_41 AC 195 ms
6,736 KB
testcase_42 AC 101 ms
4,736 KB
testcase_43 AC 119 ms
5,888 KB
testcase_44 AC 2 ms
4,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
    
	int N,Q;
	cin>>N>>Q;
	
	vector<pair<long long,long long>> V(N);
	
	
	
	for(int i=0;i<N;i++){
		scanf("%lld %lld",&V[i].first,&V[i].second);
	}
	
	V.emplace_back(-1,0);
	V.emplace_back(1000000001,0);
	
	sort(V.begin(),V.end());
	
	vector<long long> dis(V.size(),0);
	vector<long long> LL(V.size()),RR(V.size());
	long long L = 0,R = 0;
	
	for(int i=0;i<V.size();i++){
		dis[0] += abs(V[0].first - V[i].first)*V[i].second;
		R += V[i].second;
	}
	
	LL[0] = L;
	RR[0] = R;
	
	for(int i=1;i<dis.size();i++){
		long long D = V[i].first-V[i-1].first;
		dis[i] = dis[i-1] + D*(L-R);
		L += V[i].second;
		R -= V[i].second;
		LL[i] = L;
		RR[i] = R;
	}
	
	for(int i=0;i<Q;i++){
		pair<long long,long long> P(0,1000000001);
		scanf("%lld",&P.first);
		auto it = upper_bound(V.begin(),V.end(),P);
		it--;
		
		int ind = distance(V.begin(),it);
		long long ans = dis[ind];
		ans += (P.first-V[ind].first)*(LL[ind]-RR[ind]);
		cout<<ans<<endl;
	}
		
	
	
	
	
	
    return 0;
}
0