結果

問題 No.1708 Quality of Contest
ユーザー kokatsu
提出日時 2021-10-15 21:42:23
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 2,847 ms
コンパイル使用メモリ 240,144 KB
実行使用メモリ 20,308 KB
最終ジャッジ日時 2024-06-22 12:49:00
合計ジャッジ時間 8,505 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N, M ,X;
    readf("%d %d %d\n", N, M, X);

    auto A = new long[](N), B = new long[](N);
    foreach (i; 0 .. N) {
        readf("%d %d\n", A[i], B[i]);
    }

    int K;
    readf("%d\n", K);

    auto C = readln.chomp.split.to!(long[]);

    zip(A, B).sort!((a, b) => a[0] > b[0]);
    auto used = new bool[](M+1);
    auto heap = new BinaryHeap!(Array!long, "a < b")();
    foreach (i; 0 .. N) {
        if (used[B[i]]) {
            heap.insert(A[i]);
        }
        else {
            heap.insert(A[i]+X);
            used[B[i]] = true;
        }
    }

    auto cumsum = heap.array.cumulativeFold!"a + b".array;
    long res;
    foreach (c; C) {
        if (c == 0) {
            continue;
        }
        res += cumsum[c-1];
    }

    res.writeln;
}
0