結果
| 問題 |
No.2694 The Early Bird Catches The Worm
|
| コンテスト | |
| ユーザー |
MM
|
| 提出日時 | 2024-02-15 21:23:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,079 bytes |
| コンパイル時間 | 1,710 ms |
| コンパイル使用メモリ | 169,056 KB |
| 実行使用メモリ | 14,756 KB |
| 最終ジャッジ日時 | 2024-09-28 22:30:26 |
| 合計ジャッジ時間 | 16,883 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 65 TLE * 1 -- * 6 |
ソースコード
#include<bits/stdc++.h>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
using namespace std;
using ll = long long;
int main(){
// input
int N; ll H;
cin >> N >> H;
vector<ll> A(N),B(N),S(N+1); // S[i]: Bの累積和
for(int i = 0; i < N; i++)
cin >> A[i];
for(int i = 0; i < N; i++){
cin >> B[i];
S[i+1] = S[i] + B[i];
}
// solve: 尺取法
ll ans = 0;
ll tmp = 0, need_hp = 0;
int r = 0;
for(int l = 0; l < N; l++){
// right < n && (right を 1 個進めたときに条件を満たす)
while(r < N && need_hp + B[r] * (r-l+1) <= H){
tmp += A[r];
need_hp += B[r] * (r-l+1);
r++;
}
// break した状態で right は条件を満たす最大なので、何かする
// cout << l << " " << r << " " << need_hp << " " << tmp << endl;
chmax(ans,tmp);
// left をインクリメントする準備
if(l == r) r++;
else{
tmp -= A[l];
for(int i = l; i < r; i++){
need_hp -= B[i];
}
}
}
// output
cout << ans << endl;
}
MM