結果

問題 No.2601 Very Poor
ユーザー Lanatus
提出日時 2024-01-16 22:51:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 130,420 KB
最終ジャッジ日時 2025-02-18 20:18:58
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main(void) {
  long long n, x;
  cin >> n >> x;

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

  vector<long long> sum(n + 1, 0);
  for (int i = 0; i < n; ++i)
    sum[i + 1] = sum[i] + a[i];

  int r = 0;
  long long s = 0;
  long long ans = 0;

  for (int l = 0; l < n; ++l) {
    if (l == r) {
      r = l + 1;
      s = a[l];
    }

    while ((r % n) != l && s + a[r] <= x) {
      s += a[r];
      r = (r + 1) % n;
    }

    if (s <= x)
      ans = max(ans, s);

    s -= a[l];
  }

  cout << ans << endl;
  return 0;
}
0