結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー Nichi10p
提出日時 2024-03-22 22:16:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 735 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 195,420 KB
最終ジャッジ日時 2025-02-20 11:48:09
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T> bool chmax(T &a, const T &x) { return x > a ? a = x, true : false; }

int main() {
  int N, H;
  cin >> N >> H;
  vector<long long> A(N), B(N);
  for (int i=0; i < N; ++i)
    cin >> A[i];
  for (int i=0; i < N; ++i)
    cin >> B[i];

  long long answer=0, SH=0;
  vector<long long> SA(N+1), SB(N+1);
  inclusive_scan(A.begin(), A.end(), ++SA.begin());
  inclusive_scan(B.begin(), B.end(), ++SB.begin());
  for (int L=0, R=0; L < N; NULL) {
    while (R < N && SH + (R - L + 1) * B[R] <= H) {
      SH += (R - L + 1) * B[R];
      ++R;
    }
    chmax(answer, SA[R] - SA[L]);
    SH -= SB[R] - SB[L];
    ++L;
    if (R < L)
      R = L;
  }

  cout << answer << endl;
}
0