結果
| 問題 |
No.1012 荷物収集
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-02 20:12:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 242 ms / 2,000 ms |
| コード長 | 1,748 bytes |
| コンパイル時間 | 1,067 ms |
| コンパイル使用メモリ | 102,528 KB |
| 実行使用メモリ | 8,932 KB |
| 最終ジャッジ日時 | 2024-10-03 02:03:37 |
| 合計ジャッジ時間 | 9,559 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
pair<long long, long long> p[100010], x[100010];
long long ans[100010] = {};
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> que;
int main() {
int n, q;
long long l = 0, r = 0;
cin >> n >> q;
for (int i = 0; i < n; i++) {
long long x, w;
cin >> x >> w;
r += w;
p[i] = { x,w };
que.push({ x,w });
}
sort(p, p + n);
for (int i = 0; i < q; i++) {
long long X;
cin >> X;
x[i] = { X,i };
}
sort(x, x + q);
for (int i = 0; i < n; i++) {
ans[x[0].second] += abs(p[i].first - x[0].first) * p[i].second;
}
while (!que.empty()) {
if (que.top().first > x[0].first)break;
l += que.top().second, r -= que.top().second;
que.pop();
}
for (int i = 1; i < q; i++) {
ans[x[i].second] = ans[x[i - 1].second];
long long co = 0;
while (!que.empty()) {
if (que.top().first > x[i].first)break;
ans[x[i].second] -= abs(x[i - 1].first - que.top().first) * que.top().second;
ans[x[i].second] += abs(x[i].first - que.top().first) * que.top().second;
co += que.top().second, r -= que.top().second;
que.pop();
}
ans[x[i].second] += (x[i].first - x[i - 1].first) * (l - r);
l += co;
}
for (int i = 0; i < q; i++) {
cout << ans[i] << endl;
}
}