結果

問題 No.1767 BLUE to RED
ユーザー kokatsu
提出日時 2021-11-27 02:28:38
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 212,928 KB
実行使用メモリ 21,472 KB
最終ジャッジ日時 2024-06-22 13:32:00
合計ジャッジ時間 5,437 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

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

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

    A = [long.min / 2] ~ A ~ [long.max / 2];

    long res, pos;
    foreach (i; 0 .. N+1) {
        long[] C = [A[i]];
        while (pos < M && B[pos] < A[i+1]) {
            C ~= B[pos];
            ++pos;
        }

        auto l = C.length;
        if (l == 1) {
            continue;
        }

        C ~= A[i+1];

        long w;
        foreach (j; 0 .. l) {
            w = max(w, C[j+1]-C[j]);
        }
        
        res += A[i+1] - A[i] - w;
    }

    res.writeln;
}
0