結果

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

ソースコード

diff #

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

int main()
{
    int n;ll h;
    cin>>n>>h;
    vector<ll> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    ll l=0,r=0;
    vector<ll> sumb(n+1);
    for(int i=0;i<n;i++)sumb[i+1]=sumb[i]+b[i];
    ll ans=0,suma=0,tsumb=0;
    while(l<n){
        while(r<n&&tsumb+(r-l+1)*b[r]<=h){
            tsumb+=(r-l+1)*b[r];
            suma+=a[r];
            r++;
        }
        ans=max(ans,suma);
        if(l<r)suma-=a[l];
        tsumb-=(sumb[r]-sumb[l]);
        if(r==l)r++;
        l++;


    }
    cout<<ans<<endl;
    
}
0