結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー nwo
提出日時 2024-03-28 14:14:04
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 5,611 ms
コンパイル使用メモリ 311,368 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-09-30 14:44:24
合計ジャッジ時間 12,123 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ld = long double;
using ll = long long;

template<class T> bool chmax(T &a, T b)
{
	if(a<b)
	{
	a = b;
	return true;
	}
	return false;
}
template<class T> bool chmin(T &a, T b)
{
	if(a>b)
	{
		a = b;
		return true;
	}
	return false;
}

int N, H, A[1<<18], B[1<<18];
using P = pair<ll,ll>;

int main()
{
	cin >> N >> H;
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];

	vector<ll> S(N+1);
	rep(i,N) S[i+1] = S[i]+B[i];

	deque<P> q;
	ll a = 0, b = 0, ans = 0;
	int l = 0;
	rep(i,N)
	{
		q.push_back({A[i], B[i]});
		a += A[i];
		b += B[i]*(ll)q.size();
		while(b>H && !q.empty())
		{
			auto [x,y] = q.front();
			q.pop_front();
			a -= x;
			b -= S[i+1]-S[l++];
		}
		//cout << a << " " << b << endl;
		chmax(ans, a);
	}
	cout << ans << endl;
}
0