結果

問題 No.2601 Very Poor
ユーザー InTheBloomInTheBloom
提出日時 2024-01-12 21:38:19
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 2,842 ms
コンパイル使用メモリ 163,916 KB
実行使用メモリ 16,556 KB
最終ジャッジ日時 2024-03-20 19:45:46
合計ジャッジ時間 5,411 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 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 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 49 ms
16,556 KB
testcase_16 AC 49 ms
16,556 KB
testcase_17 AC 49 ms
16,556 KB
testcase_18 AC 49 ms
16,556 KB
testcase_19 AC 50 ms
16,556 KB
testcase_20 AC 50 ms
16,556 KB
testcase_21 AC 50 ms
16,556 KB
testcase_22 AC 49 ms
16,556 KB
testcase_23 AC 50 ms
16,556 KB
testcase_24 AC 50 ms
16,556 KB
testcase_25 AC 49 ms
16,556 KB
testcase_26 AC 49 ms
16,556 KB
testcase_27 AC 49 ms
16,556 KB
testcase_28 AC 49 ms
16,556 KB
testcase_29 AC 49 ms
16,556 KB
testcase_30 AC 49 ms
16,556 KB
testcase_31 AC 49 ms
16,556 KB
testcase_32 AC 50 ms
16,556 KB
testcase_33 AC 50 ms
16,556 KB
testcase_34 AC 49 ms
16,556 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N, X; readln.read(N, X);
    int[] A = readln.split.to!(int[]);

    // 累積 + 二分探索(2周)
    long[] cum = new long[](2*N+1);
    cum[0] = 0;
    for (int i = 1; i <= 2*N; i++) cum[i] = cum[i-1] + A[(i-1)%N];

    bool f (int i, int x) {
        x++; // 1-indexed
        return cum[x] - cum[i] <= X;
    }

    long ans = 0;
    foreach (i; 0..N) {
        int ok = i, ng = i+N;
        while (1 < abs(ok-ng)) {
            int mid = (ok+ng) / 2;
            if (f(i, mid)) {
                ok = mid;
            }
            else {
                ng = mid;
            }
        }

        if (cum[ok+1]-cum[i] <= X) ans = max(ans, cum[ok+1]-cum[i]);
    }

    writeln(ans);
}

void read (T...) (string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0