結果

問題 No.2601 Very Poor
ユーザー LanatusLanatus
提出日時 2024-01-16 22:51:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 1,249 ms
コンパイル使用メモリ 134,844 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-20 19:53:39
合計ジャッジ時間 4,180 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 AC 3 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 3 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 3 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 3 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 70 ms
6,548 KB
testcase_16 AC 71 ms
6,548 KB
testcase_17 AC 72 ms
6,548 KB
testcase_18 AC 71 ms
6,548 KB
testcase_19 AC 71 ms
6,548 KB
testcase_20 AC 71 ms
6,548 KB
testcase_21 AC 71 ms
6,548 KB
testcase_22 AC 71 ms
6,548 KB
testcase_23 AC 71 ms
6,548 KB
testcase_24 AC 71 ms
6,548 KB
testcase_25 AC 71 ms
6,548 KB
testcase_26 AC 71 ms
6,548 KB
testcase_27 AC 71 ms
6,548 KB
testcase_28 AC 71 ms
6,548 KB
testcase_29 AC 71 ms
6,548 KB
testcase_30 AC 71 ms
6,548 KB
testcase_31 AC 71 ms
6,548 KB
testcase_32 AC 71 ms
6,548 KB
testcase_33 AC 71 ms
6,548 KB
testcase_34 AC 71 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

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