結果

問題 No.1012 荷物収集
ユーザー 沙耶花沙耶花
提出日時 2020-03-20 21:50:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 210,712 KB
実行使用メモリ 7,400 KB
最終ジャッジ日時 2024-05-08 21:43:09
合計ジャッジ時間 9,074 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 172 ms
7,400 KB
testcase_05 AC 169 ms
7,396 KB
testcase_06 AC 169 ms
7,396 KB
testcase_07 AC 166 ms
7,268 KB
testcase_08 AC 168 ms
7,268 KB
testcase_09 AC 170 ms
7,204 KB
testcase_10 AC 170 ms
7,268 KB
testcase_11 AC 170 ms
7,136 KB
testcase_12 AC 169 ms
7,272 KB
testcase_13 AC 166 ms
7,264 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 127 ms
5,376 KB
testcase_25 AC 158 ms
6,340 KB
testcase_26 AC 54 ms
6,176 KB
testcase_27 AC 13 ms
5,376 KB
testcase_28 AC 141 ms
6,848 KB
testcase_29 AC 34 ms
7,232 KB
testcase_30 AC 142 ms
7,256 KB
testcase_31 AC 100 ms
5,376 KB
testcase_32 AC 61 ms
5,376 KB
testcase_33 AC 110 ms
5,376 KB
testcase_34 AC 127 ms
5,376 KB
testcase_35 AC 121 ms
6,436 KB
testcase_36 AC 126 ms
5,376 KB
testcase_37 AC 37 ms
6,852 KB
testcase_38 AC 130 ms
5,748 KB
testcase_39 AC 51 ms
5,376 KB
testcase_40 AC 71 ms
5,376 KB
testcase_41 AC 171 ms
7,196 KB
testcase_42 AC 91 ms
5,376 KB
testcase_43 AC 103 ms
6,128 KB
testcase_44 AC 2 ms
5,376 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