結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー MMMM
提出日時 2024-02-15 20:51:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,303 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 169,760 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-16 23:34:06
合計ジャッジ時間 9,226 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 40 ms
6,676 KB
testcase_25 AC 35 ms
6,676 KB
testcase_26 AC 48 ms
6,676 KB
testcase_27 AC 62 ms
6,676 KB
testcase_28 AC 70 ms
6,676 KB
testcase_29 AC 23 ms
6,676 KB
testcase_30 RE -
testcase_31 AC 72 ms
6,676 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 7 ms
6,676 KB
testcase_35 AC 58 ms
6,676 KB
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 21 ms
6,676 KB
testcase_40 AC 64 ms
6,676 KB
testcase_41 AC 32 ms
6,676 KB
testcase_42 AC 5 ms
6,676 KB
testcase_43 AC 12 ms
6,676 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 41 ms
6,676 KB
testcase_47 AC 43 ms
6,676 KB
testcase_48 AC 75 ms
6,676 KB
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 AC 50 ms
6,676 KB
testcase_75 RE -
権限があれば一括ダウンロードができます

ソースコード

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;

void validate(ll x, ll m){
  assert(x >= 1 && x <= m);
}

int main(){
  // input
  int N; ll H;
  cin >> N >> H;
  validate(N,100000);
  validate(H,1000000000);
  vector<ll> A(N),B(N),S(N+1); // S[i]: Bの累積和
  for(int i = 0; i < N; i++){
    cin >> A[i];
    validate(A[i],1000000000);
  }
  for(int i = 0; i < N; i++){
    cin >> B[i];
    validate(B[i],1000000000);
    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)更新できることに気付くのが本問のポイント
    }
  }
  
  // output
  cout << ans << endl;
}
0