結果

問題 No.2601 Very Poor
ユーザー GlinTFrauleinGlinTFraulein
提出日時 2024-01-12 22:57:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 2,132 bytes
コンパイル時間 4,318 ms
コンパイル使用メモリ 263,884 KB
実行使用メモリ 14,396 KB
最終ジャッジ日時 2024-03-20 19:49:49
合計ジャッジ時間 7,206 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,548 KB
testcase_05 AC 3 ms
6,548 KB
testcase_06 AC 3 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 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 74 ms
14,396 KB
testcase_16 AC 74 ms
14,396 KB
testcase_17 AC 74 ms
14,396 KB
testcase_18 AC 75 ms
14,396 KB
testcase_19 AC 74 ms
14,396 KB
testcase_20 AC 75 ms
14,396 KB
testcase_21 AC 74 ms
14,396 KB
testcase_22 AC 74 ms
14,396 KB
testcase_23 AC 74 ms
14,396 KB
testcase_24 AC 74 ms
14,396 KB
testcase_25 AC 74 ms
14,396 KB
testcase_26 AC 74 ms
14,396 KB
testcase_27 AC 74 ms
14,396 KB
testcase_28 AC 74 ms
14,396 KB
testcase_29 AC 74 ms
14,396 KB
testcase_30 AC 74 ms
14,396 KB
testcase_31 AC 74 ms
14,396 KB
testcase_32 AC 74 ms
14,396 KB
testcase_33 AC 74 ms
14,396 KB
testcase_34 AC 74 ms
14,396 KB
testcase_35 AC 3 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define elif else if
#define ll long long
#define vll vector<long long>
#define vec vector
#define embk emplace_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep3(i, n, k) for (ll i = k; i < n; i++)
#define all(a) a.begin(), a.end()
#define YNeos(bool) (bool ? "Yes" : "No")
#define vllin(a, n) vll a(n); rep(i, n) cin >> a[i]
#define vchin(a, n) vec<char> a(n); rep(i, n) cin >> a[i]


using namespace std;
const ll INF = 1LL << 60;
const ll mod = 998244353;
//const ll mod = 1000000007;
const double pi = acos(-1);

//#ifdef ATCODER
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
//#endif

//Prototype declaration
template <class T, class... U> void gin(T&&, U&&...);
template <typename T> vector<T> read(ll);
template <typename T> void printvec(const T&);
template <class T, class... U> void printany(T&&, U&&...);

vector<ll> ruisekiwa (vector<ll> a) {
  vector<ll> suma(a.size() + 1);
  suma.at(0) = 0;
  for (int i = 0; i < a.size(); i++) suma.at(i + 1) = suma.at(i) + a.at(i);
  return suma;
}

//Main Program
int main() {
  ll n, x; gin(n, x);
  vllin(a, n);
  vll a2(n*2);
  rep(i, n) {
    a2[i] = a[i];
    a2[i+n] = a[i];
  }

  auto ruia2 = ruisekiwa(a2);
  ll ans = 0;
  ll l = 0, r = 1;
  while(l != n*2 && r != n*2) {
    if (ruia2[r] - ruia2[l] <= x && r - l <= n) ans = max(ans, ruia2[r] - ruia2[l]);

    if (r == n*2) l++;
    elif(l == r) r++;
    elif (ruia2[r+1] - ruia2[l] <= x) r++;
    else l++;
  }
  cout << ans << endl;
}


//Function Definition
void gin() {return;}
template <class T, class... U> void gin(T&& now,  U&&... next) {
  cin >> now;
  gin(forward<U> (next)...);
}

template <typename T> vector<T> read(ll n) {
  vector<T> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  return v;
}

template <typename T> void printvec(const T& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i];
    if (i == a.size() - 1) cout << endl;
    else cout << ' ';
  }
}

void printany() {cout << endl;}
template <class T, class... U> void printany(T&& now, U&&... next) {
  cout << now << ' ';
  printany(forward<U> (next)...);
}
0