結果

問題 No.1008 Bench Craftsman
ユーザー nebukuro09nebukuro09
提出日時 2020-03-06 22:26:16
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,477 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 111,656 KB
実行使用メモリ 28,156 KB
最終ジャッジ日時 2023-09-04 06:17:11
合計ジャッジ時間 4,481 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 34 ms
12,888 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 105 ms
20,736 KB
testcase_16 WA -
testcase_17 AC 105 ms
20,804 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 40 ms
10,352 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 35 ms
12,916 KB
testcase_26 AC 28 ms
10,704 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 N = s[0];
    auto M = s[1];
    auto A = readln.split.map!(to!long).array;
    auto XW = iota(M).map!(_ => readln.split.map!(to!int).array).array;

    auto B = new long[](N);
    foreach (xw; XW) B[xw[0]-1] += xw[1];

    if (N.iota.map!(i => A[i] <= B[i]).any) {
        writeln(-1);
        return;
    }

    long[] calc(int[] X, long[] Y) {
        auto LtoR = new long[](N);
        auto RtoL = new long[](N);

        foreach (i; 0..M) {
            auto idx = X[i];
            if (idx < N - 1) LtoR[idx+1] += Y[i];
            if (idx > 0) RtoL[idx-1] += Y[i];
        }

        foreach (i; 0..N-1) LtoR[i+1] += LtoR[i];
        foreach (i; 0..N-1) LtoR[i+1] += LtoR[i];
        foreach_reverse (i; 1..N) RtoL[i-1] += RtoL[i];
        foreach_reverse (i; 1..N) RtoL[i-1] += RtoL[i];

        return N.iota.map!(i => LtoR[i] + RtoL[i]).array;
    }

    auto X = XW.map!(xw => xw[0].to!int-1).array;
    auto Y1 = new long[](M); Y1[] = 1;
    auto Y2 = XW.map!(xw => xw[1].to!long).array;
    auto C = calc(X, Y1);
    auto D = calc(X, Y2);

    auto S = Y2.sum;
    auto ans = 0L;

    foreach (i, a; A) if (a <= S) {
        ans = max(ans, (S - a) / C[i] + ((S - a) % C[i] > 0));
    }

    ans.writeln;
}
0