結果

問題 No.2601 Very Poor
ユーザー t98slider
提出日時 2024-02-04 20:31:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 171,164 KB
実行使用メモリ 7,200 KB
最終ジャッジ日時 2024-09-30 06:41:14
合計ジャッジ時間 3,577 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    vector<ll> s(2 * n + 1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }
    for(int i = 0; i < n; i++) s[i + 1 + n] = s[i + n] + a[i];
    ll ans = 0;
    for(int l = 0, r = 0; l < n; l++){
        r = max(r, l);
        while(r <= l + n && s[r] <= s[l] + x){
            ans = max(ans, s[r] - s[l]);
            r++;
        }
    }
    cout << ans << '\n';
}
0