結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー kokosei
提出日時 2024-03-22 21:51:17
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 2,749 ms
コンパイル使用メモリ 243,320 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-09-30 11:19:47
合計ジャッジ時間 7,242 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int N, H;
int A[202020], B[202020];
ll S[202020], T[202020];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N >> H;
    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++){
        S[i + 1] = S[i] + (ll)(i + 1) * B[i];
        T[i + 1] = T[i] + B[i];
    }
    ll sum = 0, ans = 0;
    for(int l = 0, r = 0;l < N;){
        while(r < N){
            ll wr = S[r + 1] - l * T[r + 1];
            ll wl = S[l] - l * T[l];
            if(wr - wl > H)break;
            sum += A[r];
            r++;
        }
        ans = max(ans, sum);
        sum -= A[l];
        l++;
    }
    cout << ans << endl;
    return 0;
}
0