結果

問題 No.1012 荷物収集
ユーザー chocoruskchocorusk
提出日時 2020-03-20 21:45:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 1,010 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 117,740 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-15 05:10:08
合計ジャッジ時間 8,463 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
	int n, q;
	cin>>n>>q;
	vector<P> v(n);
	for(int i=0; i<n; i++){
		cin>>v[i].first>>v[i].second;
	}
	sort(v.begin(), v.end());
	ll ws[100010], wxs[100010];
	ws[0]=0, wxs[0]=0;
	for(int i=0; i<n; i++){
		ws[i+1]=ws[i]+v[i].second;
		wxs[i+1]=wxs[i]+v[i].first*v[i].second;
	}
	while(q--){
		ll x;
		cin>>x;
		int k=lower_bound(v.begin(), v.end(), P(x, 0))-v.begin();
		ll ans=x*ws[k]-wxs[k]+(wxs[n]-wxs[k])-x*(ws[n]-ws[k]);
		cout<<ans<<endl;
	}
	return 0;
}
0