結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー VvyLwVvyLw
提出日時 2024-03-23 17:04:44
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,478 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 142,228 KB
実行使用メモリ 17,096 KB
最終ジャッジ日時 2024-03-23 17:04:52
合計ジャッジ時間 7,888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 0 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 21 ms
8,820 KB
testcase_25 AC 20 ms
7,520 KB
testcase_26 AC 23 ms
8,896 KB
testcase_27 AC 33 ms
10,976 KB
testcase_28 AC 34 ms
10,928 KB
testcase_29 AC 13 ms
6,676 KB
testcase_30 AC 55 ms
13,024 KB
testcase_31 AC 31 ms
11,012 KB
testcase_32 AC 59 ms
16,552 KB
testcase_33 AC 58 ms
14,636 KB
testcase_34 AC 3 ms
6,676 KB
testcase_35 AC 30 ms
11,120 KB
testcase_36 AC 39 ms
11,044 KB
testcase_37 AC 66 ms
16,848 KB
testcase_38 AC 43 ms
11,676 KB
testcase_39 AC 11 ms
6,676 KB
testcase_40 AC 31 ms
11,172 KB
testcase_41 AC 17 ms
7,468 KB
testcase_42 AC 3 ms
6,676 KB
testcase_43 AC 6 ms
6,676 KB
testcase_44 AC 68 ms
14,476 KB
testcase_45 AC 68 ms
14,496 KB
testcase_46 AC 21 ms
7,704 KB
testcase_47 AC 20 ms
8,844 KB
testcase_48 AC 35 ms
10,884 KB
testcase_49 AC 48 ms
14,840 KB
testcase_50 AC 46 ms
14,824 KB
testcase_51 AC 46 ms
14,840 KB
testcase_52 AC 46 ms
14,832 KB
testcase_53 AC 44 ms
14,812 KB
testcase_54 AC 73 ms
16,996 KB
testcase_55 AC 76 ms
17,064 KB
testcase_56 AC 73 ms
17,080 KB
testcase_57 AC 72 ms
17,020 KB
testcase_58 AC 73 ms
17,008 KB
testcase_59 AC 72 ms
17,040 KB
testcase_60 AC 75 ms
17,096 KB
testcase_61 AC 76 ms
16,988 KB
testcase_62 AC 79 ms
17,012 KB
testcase_63 AC 89 ms
17,016 KB
testcase_64 AC 73 ms
17,056 KB
testcase_65 AC 77 ms
17,060 KB
testcase_66 AC 77 ms
17,000 KB
testcase_67 AC 73 ms
17,028 KB
testcase_68 AC 71 ms
17,020 KB
testcase_69 AC 56 ms
13,644 KB
testcase_70 AC 53 ms
13,644 KB
testcase_71 AC 53 ms
13,644 KB
testcase_72 AC 54 ms
13,644 KB
testcase_73 AC 55 ms
13,644 KB
testcase_74 AC 27 ms
10,548 KB
testcase_75 AC 56 ms
13,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio: readf, readln, writeln;
import std.conv: to;
import std.string: split;
struct PrefixSum(T) {
import std.algorithm.iteration: cumulativeFold;
import std.array: array, insertInPlace;
private:
    int n;
    bool not_built;
    T[] s;
public:
    this(const int n) {
        this.n = n;
        not_built = true;
        s = new T[n + 1];
    }
    this(const T[] a) {
        s = cumulativeFold!"a + b"(a, cast(T)0).array;
        insertInPlace(s, 0, 0);
    }
    T[] get(){ return s; }
    T sum(const int l, const int r) const { return s[r] - s[l]; }
    void add(const int l, const int r, const T x) {
        assert(not_built);
        s[l] += x;
        s[r] -= x;
    }
    T[] build() {
        assert(not_built);
        auto res = cumulativeFold!"a + b"(s).array;
        not_built = false;
        return res[0..n];
    }
}
void chmax(T, U)(ref T a, const U b) {
    if(a < b) {
		a = b;
	}
}
void main() {
    int n, h;
    readf("%d %d\n", &n, &h);
    const a = readln.split.to!(int[]);
    const b = readln.split.to!(long[]);
    auto ps = new PrefixSum!long(b);
    long ans = 0, s = 0, t = 0;
    for(int l = 0, r = 0; l < n; ++l) {
        while(r < n && t + (r - l + 1) * b[r] <= h) {
            s += a[r];
            t += (r - l + 1) * b[r];
            r++;
        }
        if(l == r) {
            r++;
        } else {
            chmax(ans, s);
            s -= a[l];
            t -= ps.sum(l, r);
        }
    }
    writeln(ans);
}
0