結果
問題 | No.2694 The Early Bird Catches The Worm |
ユーザー |
![]() |
提出日時 | 2024-02-15 19:42:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 1,130 bytes |
コンパイル時間 | 1,625 ms |
コンパイル使用メモリ | 169,624 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-09-28 22:29:53 |
合計ジャッジ時間 | 9,869 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 72 |
ソースコード
#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(){// inputint 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];need_hp -= S[r]-S[l]; // 累積和で差分をO(1)更新できることに気付くのが本問のポイント}}// outputcout << ans << endl;}