結果

問題 No.1012 荷物収集
ユーザー rniyarniya
提出日時 2020-03-20 21:54:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 3,193 ms
コンパイル使用メモリ 174,432 KB
実行使用メモリ 11,272 KB
最終ジャッジ日時 2023-08-21 16:21:49
合計ジャッジ時間 6,745 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 49 ms
10,108 KB
testcase_05 AC 49 ms
11,272 KB
testcase_06 AC 49 ms
10,108 KB
testcase_07 AC 49 ms
10,880 KB
testcase_08 AC 49 ms
10,112 KB
testcase_09 AC 49 ms
10,308 KB
testcase_10 AC 49 ms
11,168 KB
testcase_11 AC 48 ms
9,836 KB
testcase_12 AC 49 ms
10,036 KB
testcase_13 AC 49 ms
10,248 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 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
7,096 KB
testcase_25 AC 57 ms
9,724 KB
testcase_26 AC 32 ms
6,532 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 56 ms
10,168 KB
testcase_29 AC 35 ms
6,740 KB
testcase_30 AC 58 ms
9,708 KB
testcase_31 AC 24 ms
5,616 KB
testcase_32 AC 20 ms
4,616 KB
testcase_33 AC 30 ms
6,032 KB
testcase_34 AC 32 ms
6,024 KB
testcase_35 AC 49 ms
10,500 KB
testcase_36 AC 30 ms
5,828 KB
testcase_37 AC 33 ms
6,488 KB
testcase_38 AC 45 ms
7,168 KB
testcase_39 AC 21 ms
4,900 KB
testcase_40 AC 25 ms
5,868 KB
testcase_41 AC 63 ms
10,300 KB
testcase_42 AC 31 ms
6,104 KB
testcase_43 AC 42 ms
6,772 KB
testcase_44 AC 2 ms
4,380 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