結果

問題 No.1012 荷物収集
ユーザー tarattata1tarattata1
提出日時 2020-03-20 22:43:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,496 bytes
コンパイル時間 1,060 ms
コンパイル使用メモリ 85,816 KB
実行使用メモリ 5,876 KB
最終ジャッジ日時 2023-08-21 17:46:59
合計ジャッジ時間 5,924 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 49 ms
5,752 KB
testcase_05 AC 50 ms
5,760 KB
testcase_06 AC 49 ms
5,760 KB
testcase_07 AC 50 ms
5,824 KB
testcase_08 AC 50 ms
5,808 KB
testcase_09 AC 50 ms
5,804 KB
testcase_10 AC 49 ms
5,812 KB
testcase_11 AC 50 ms
5,764 KB
testcase_12 AC 50 ms
5,812 KB
testcase_13 AC 50 ms
5,876 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,508 KB
testcase_20 AC 2 ms
4,388 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 45 ms
4,384 KB
testcase_25 AC 59 ms
4,956 KB
testcase_26 AC 31 ms
4,700 KB
testcase_27 AC 8 ms
4,384 KB
testcase_28 AC 57 ms
5,260 KB
testcase_29 AC 32 ms
5,488 KB
testcase_30 AC 58 ms
5,752 KB
testcase_31 AC 23 ms
4,384 KB
testcase_32 AC 20 ms
4,380 KB
testcase_33 AC 31 ms
4,384 KB
testcase_34 AC 34 ms
4,384 KB
testcase_35 AC 49 ms
5,012 KB
testcase_36 AC 30 ms
4,388 KB
testcase_37 AC 31 ms
5,676 KB
testcase_38 AC 47 ms
4,504 KB
testcase_39 AC 22 ms
4,384 KB
testcase_40 AC 25 ms
4,384 KB
testcase_41 AC 65 ms
5,548 KB
testcase_42 AC 31 ms
4,380 KB
testcase_43 AC 42 ms
4,756 KB
testcase_44 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

void solve()
{
    int n, Q;
    scanf("%d%d", &n, &Q);
    vector<pair<int, int> > z(n);   // x,w
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d%d", &z[i].first, &z[i].second);
    }
    sort(z.begin(), z.end());

    vector<ll> sw(n + 1), sxw(n + 1), xx(n);
    for (i = 0; i < n; i++) {
        int x = z[i].first;
        int w = z[i].second;
        sw[i + 1] = sw[i] + w;
        sxw[i + 1] = sxw[i] + (ll)w*x;
        xx[i] = x;
    }

    for (i = 0; i < Q; i++) {
        int x0;
        scanf("%d", &x0);
        int k = lower_bound(xx.begin(), xx.end(), x0) - xx.begin();
        ll ans0 = x0 * sw[k] - sxw[k];
        ll ans1 = -x0 * (sw[n] - sw[k]) + (sxw[n] - sxw[k]);
        ll ans = ans0 + ans1;
        printf("%lld\n", ans);
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}
0