結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー MM
提出日時 2024-02-15 23:07:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,170 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 170,408 KB
実行使用メモリ 14,752 KB
最終ジャッジ日時 2024-09-28 22:35:17
合計ジャッジ時間 17,368 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 65 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#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];
      // 本解ではここは累積和。愚直に計算した結果がTLEしてほしい
      for(int i = l; i < r; i++){
      	need_hp -= B[i];
      }
    }
  }
  
  // output
  cout << ans << endl;
}
0