結果

問題 No.1012 荷物収集
ユーザー momoharamomohara
提出日時 2020-03-20 22:16:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 2,211 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 108,288 KB
実行使用メモリ 6,312 KB
最終ジャッジ日時 2023-08-21 16:58:13
合計ジャッジ時間 5,664 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 46 ms
6,264 KB
testcase_05 AC 46 ms
6,196 KB
testcase_06 AC 45 ms
6,224 KB
testcase_07 AC 45 ms
6,204 KB
testcase_08 AC 46 ms
6,144 KB
testcase_09 AC 45 ms
6,288 KB
testcase_10 AC 46 ms
6,288 KB
testcase_11 AC 46 ms
6,140 KB
testcase_12 AC 46 ms
6,220 KB
testcase_13 AC 46 ms
6,272 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 43 ms
4,552 KB
testcase_25 AC 58 ms
5,668 KB
testcase_26 AC 31 ms
5,192 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 56 ms
5,876 KB
testcase_29 AC 32 ms
6,312 KB
testcase_30 AC 58 ms
6,312 KB
testcase_31 AC 20 ms
4,380 KB
testcase_32 AC 19 ms
4,376 KB
testcase_33 AC 29 ms
4,380 KB
testcase_34 AC 31 ms
4,380 KB
testcase_35 AC 48 ms
5,344 KB
testcase_36 AC 27 ms
4,376 KB
testcase_37 AC 31 ms
5,880 KB
testcase_38 AC 47 ms
4,828 KB
testcase_39 AC 21 ms
4,376 KB
testcase_40 AC 24 ms
4,376 KB
testcase_41 AC 63 ms
5,876 KB
testcase_42 AC 29 ms
4,416 KB
testcase_43 AC 41 ms
5,080 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9+7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}

void solve() {
	ll n, q;
	cin >> n >> q;

	vector<P> xw(n);
	REP(i, n) cin >> xw[i].first >> xw[i].second;
	sort(all(xw));

	Array sum(n + 1, 0);
	REP(i, n) sum[i + 1] = sum[i] + xw[i].first * xw[i].second;

	Array sum_w(n + 1, 0);
	REP(i, n) sum_w[i + 1] = sum_w[i] + xw[i].second;
	

	REP(i, q) {
		ll x;
		cin >> x;
		auto it = lower_bound(all(xw), make_pair( x,0LL));
		ll xn = it - xw.begin();
		ll ans = 0;
		ans += (sum[n] - sum[xn]) - x * (sum_w[n] - sum_w[xn]);
		ans += x * (sum_w[xn] - sum_w[0]) - (sum[xn] - sum[0]);
		cout << ans << en;
	}

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}
0