結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー eve__fuyuki
提出日時 2024-03-23 04:44:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 195,236 KB
最終ジャッジ日時 2025-02-20 13:03:16
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    long long h;
    cin >> n >> h;
    vector<long long> a(n), b(n), bj(n), acum(n + 1), bcum(n + 1), bjcum(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        bj[i] = (i + 1) * b[i];
        acum[i + 1] = acum[i] + a[i];
        bcum[i + 1] = bcum[i] + b[i];
        bjcum[i + 1] = bjcum[i] + bj[i];
    }
    long long ans = 0, score = 0;
    for (int l = 0, r = 0; l < n; l++) {
        while (r < n &&
               bjcum[r + 1] - bjcum[l] - l * (bcum[r + 1] - bcum[l]) <= h) {
            score += a[r];
            r++;
        }
        // cout << l << " " << r << " " << score << endl;
        ans = max(ans, score);
        score -= a[l];
        if (l == r) {
            r++;
            score += a[l];
        }
    }
    cout << ans << endl;
}
0