結果

問題 No.1012 荷物収集
ユーザー rniyarniya
提出日時 2020-03-20 21:54:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 176,596 KB
実行使用メモリ 10,008 KB
最終ジャッジ日時 2024-05-08 21:51:00
合計ジャッジ時間 6,447 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 47 ms
9,876 KB
testcase_05 AC 47 ms
9,884 KB
testcase_06 AC 47 ms
9,876 KB
testcase_07 AC 47 ms
9,756 KB
testcase_08 AC 47 ms
9,752 KB
testcase_09 AC 46 ms
9,884 KB
testcase_10 AC 47 ms
10,008 KB
testcase_11 AC 47 ms
9,884 KB
testcase_12 AC 47 ms
9,880 KB
testcase_13 AC 47 ms
10,008 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 42 ms
7,120 KB
testcase_25 AC 55 ms
9,580 KB
testcase_26 AC 31 ms
6,756 KB
testcase_27 AC 9 ms
5,376 KB
testcase_28 AC 53 ms
9,484 KB
testcase_29 AC 33 ms
6,948 KB
testcase_30 AC 54 ms
9,732 KB
testcase_31 AC 24 ms
5,904 KB
testcase_32 AC 19 ms
5,376 KB
testcase_33 AC 30 ms
6,316 KB
testcase_34 AC 31 ms
6,328 KB
testcase_35 AC 46 ms
9,108 KB
testcase_36 AC 29 ms
6,196 KB
testcase_37 AC 31 ms
6,916 KB
testcase_38 AC 43 ms
7,232 KB
testcase_39 AC 20 ms
5,376 KB
testcase_40 AC 25 ms
6,284 KB
testcase_41 AC 59 ms
9,692 KB
testcase_42 AC 30 ms
6,336 KB
testcase_43 AC 39 ms
6,940 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin >> N >> Q;
    vector<ll> x(N),w(N);
    for (int i=0;i<N;++i) cin >> x[i] >> w[i];
    vector<ll> X(Q);
    for (int i=0;i<Q;++i) cin >> X[i];
    vector<pair<ll,ll>> pos;
    for (int i=0;i<N;++i) pos.emplace_back(x[i],w[i]);
    for (int i=0;i<Q;++i) pos.emplace_back(X[i],-i);
    sort(pos.begin(),pos.end());
    ll now=0,last=0,cnt=0,sum=0;
    for (int i=0;i<N;++i) now+=x[i]*w[i],sum+=w[i];
    vector<ll> ans(Q);
    for (auto p:pos){
        int y=p.first,id=p.second;
        now+=cnt*(y-last);
        now-=(sum-cnt)*(y-last);
        if (id>0) cnt+=id;
        else ans[-id]=now;
        last=y;
    }
    for (int i=0;i<Q;++i) cout << ans[i] << '\n';
}
0