結果
| 問題 | No.1012 荷物収集 |
| コンテスト | |
| ユーザー |
rxoxixyxd
|
| 提出日時 | 2020-03-20 23:07:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,832 bytes |
| コンパイル時間 | 2,076 ms |
| コンパイル使用メモリ | 181,360 KB |
| 実行使用メモリ | 27,584 KB |
| 最終ジャッジ日時 | 2024-12-15 08:21:44 |
| 合計ジャッジ時間 | 75,353 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 WA * 18 TLE * 22 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;
int main()
{
int n, q;
cin >> n >> q;
vector<ll> x(n);
vector<ll> w(n);
rep(i, n) {
cin >> x[i] >> w[i];
}
ll sum_w = SUM(w);
map<ll, ll> mp_l;
map<ll, ll> mp_r;
map<ll, ll> mp_lw;
map<ll, ll> mp_rw;
for (int i = 0; i < n; i++) {
ll cost = 0;
ll weight = 0;
for (int j = 0; j <= i; j++) {
cost += abs(x[i] - x[j]) * w[j];
weight += w[j];
}
mp_l[x[i]] = cost;
mp_lw[x[i]] = weight;
}
for (int i = n-1; i >= 0; i--) {
ll cost = 0;
ll weight = 0;
for (int j = n-1; j >= i; j--) {
cost += abs(x[i] - x[j]) * w[j];
weight += w[j];
}
mp_r[x[i]] = cost;
mp_rw[x[i]] = weight;
}
sort(ALL(x));
rep(i, q) {
ll target;
cin >> target;
// 1番近い xi を求める
auto itr1 = lower_bound(ALL(x), target);
if (itr1 != x.begin() || itr1 == x.end()) itr1--;
auto itr2 = upper_bound(ALL(x), target);
if (itr2 == x.end()) itr2--;
ll ans = 0;
if (*itr1 < target) {
ans += mp_l[*itr1] + abs(*itr1 - target) * mp_lw[*itr1];
}
if (*itr2 > target) {
ans += mp_r[*itr2] + abs(*itr2 - target) * mp_rw[*itr2];
}
cout << ans << endl;
}
return 0;
}
rxoxixyxd