結果

問題 No.1012 荷物収集
ユーザー ngtkanangtkana
提出日時 2020-04-08 23:16:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 4,156 ms
コンパイル使用メモリ 209,944 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2023-09-26 11:08:51
合計ジャッジ時間 10,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 46 ms
6,912 KB
testcase_05 AC 45 ms
7,132 KB
testcase_06 AC 45 ms
6,936 KB
testcase_07 AC 46 ms
7,012 KB
testcase_08 AC 46 ms
6,856 KB
testcase_09 AC 45 ms
7,784 KB
testcase_10 AC 46 ms
6,988 KB
testcase_11 AC 46 ms
6,876 KB
testcase_12 AC 45 ms
6,984 KB
testcase_13 AC 46 ms
7,848 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 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 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,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 42 ms
5,044 KB
testcase_25 AC 55 ms
6,356 KB
testcase_26 AC 30 ms
5,912 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 54 ms
6,376 KB
testcase_29 AC 34 ms
6,820 KB
testcase_30 AC 56 ms
6,792 KB
testcase_31 AC 20 ms
4,376 KB
testcase_32 AC 19 ms
4,380 KB
testcase_33 AC 28 ms
4,376 KB
testcase_34 AC 29 ms
4,380 KB
testcase_35 AC 46 ms
6,360 KB
testcase_36 AC 26 ms
4,384 KB
testcase_37 AC 32 ms
7,500 KB
testcase_38 AC 44 ms
5,604 KB
testcase_39 AC 20 ms
4,480 KB
testcase_40 AC 24 ms
4,380 KB
testcase_41 AC 62 ms
6,708 KB
testcase_42 AC 30 ms
4,472 KB
testcase_43 AC 41 ms
5,900 KB
testcase_44 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,q;std::cin>>n>>q;
    std::vector<std::pair<lint,lint>>xw(n);
    for(auto&&p:xw)std::cin>>p.first>>p.second;
    xw.emplace_back(1'000'000'000,0);
    n++;
    std::sort(ALL(xw));
    std::vector<lint>x(n),w(n+1),dp(n);
    for(lint i=0;i<n;i++){
        std::tie(x.at(i),w.at(i+1))=xw.at(i);
    }
    std::partial_sum(ALL(w),w.begin());
    for(lint i=1;i<n;i++){
        dp.at(0)+=(x.at(i)-x.at(0))*(w.at(i+1)-w.at(i));
    }
    for(lint i=1;i<n;i++){
        dp.at(i)+=dp.at(i-1)+(2*w.at(i)-w.at(n))*(x.at(i)-x.at(i-1));
    }
    while(q--){
        lint X;std::cin>>X;
        lint i=std::lower_bound(ALL(x),X)-x.begin();
        std::cout<<dp.at(i)+(w.at(n)-2*w.at(i))*(x.at(i)-X)<<'\n';
    }
}
0