結果

問題 No.2601 Very Poor
ユーザー vjudge1
提出日時 2025-07-19 20:37:48
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 4,556 ms
コンパイル使用メモリ 212,312 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2025-07-19 20:37:57
合計ジャッジ時間 7,516 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

int n, x;

int main() {
  //freopen("rental.in" , "r", stdin);
  //freopen("rental.out" , "w", stdout);
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> x;

  vector<int64_t> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  int64_t m = 0;
  for (int i = 0; i < n; ++i) m += a[i];

  vector<int64_t> sum(n * 2 + 1);
  for (int i = 0; i < 2 * n; ++i)
    sum[i + 1] = sum[i] + a[i % n];

  int64_t ans = 0;
  for (int i = 0; i < n; ++i) {
    auto it = lower_bound(sum.begin(), sum.end(), x + sum[i] + 1);
    it--;
    int64_t tmp = *it - sum[i];
    ans = max(min(tmp, m), ans);
  }
  cout << ans;
  return 0;
}




0