結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー tnakao0123
提出日時 2024-04-26 19:45:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 41,340 KB
最終ジャッジ日時 2025-02-21 09:10:34
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 72
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |   scanf("%d%d", &n, &h);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:31:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |   for (int i = 0; i < n; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~
main.cpp:32:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |   for (int i = 0; i < n; i++) scanf("%d", bs + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2694.cc:  No.2694 The Early Bird Catches The Worm - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], bs[MAX_N];
ll ass[MAX_N + 1], bss[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, h;
  scanf("%d%d", &n, &h);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++) scanf("%d", bs + i);

  for (int i = 0; i < n; i++) ass[i + 1] = ass[i] + as[i];
  for (int i = 0; i < n; i++) bss[i + 1] = bss[i] + bs[i];

  ll maxx = 0, y = 0;
  for (int i = 0, j = 0; j < n; i++) {
    while (j < n && y + (ll)bs[j] * (j + 1 - i) <= h) {
      y += (ll)bs[j] * (j + 1 - i);
      j++;
    }

    maxx = max(maxx, ass[j] - ass[i]);
    //printf(" %d,%d: x=%lld, y=%lld\n", i, j, ass[j] - ass[i], y);

    y -= bss[j] - bss[i];
  }

  printf("%lld\n", maxx);
  
  return 0;
}
0