結果

問題 No.957 植林
コンテスト
ユーザー nebukuro09
提出日時 2019-12-19 23:14:55
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
WA  
実行時間 -
コード長 931 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,206 ms
コンパイル使用メモリ 106,616 KB
実行使用メモリ 7,780 KB
最終ジャッジ日時 2026-03-06 09:34:55
合計ジャッジ時間 2,693 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = iota(H).map!(_ => readln.split.map!(to!long).array).array;
    auto R = readln.split.map!(to!long).array;
    auto C = readln.split.map!(to!long).array;

    foreach (i; 0..H) A[i] ~= R[i] - A[i].sum;
    A.sort!"a.back > b.back";

    long csum = 0;
    foreach (j; 0..W) foreach (i; 0..H) C[j] -= A[i][j];
    foreach (j; 0..W) csum += max(0L, C[j]);

    auto ans = csum;
    auto tmp = csum;

    foreach (i; 0..H) {
        tmp += A[i].back;
        foreach (j; 0..W) {
            C[j] += A[i][j];
            tmp += max(0L, C[j] - max(C[j] - A[i][j], 0L));
        }
        ans = max(ans, tmp);
    }

    ans.writeln;
}
0