結果

問題 No.2601 Very Poor
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2024-01-12 22:01:12
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 636 bytes
コンパイル時間 2,552 ms
コンパイル使用メモリ 244,932 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-30 06:22:36
合計ジャッジ時間 4,206 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
    int n,x;
    cin >> n >> x;
    vector<int> A(2*n);
    for (int i = 0; i < n; i++){
        cin >> A[i];
        A[i+n] = A[i];
    }

    int ans = 0;

    int r=0,count=0;

    for (int l = 0; l < n; l++){
        while (r < 2*n && (r-l) < n)
        {
            if (count + A[r] <= x){
                count += A[r];
                r++;
            } else{
                break;
            }
        }
        ans = max(ans,count);
        count -= A[l];
        
    }
    cout << ans << endl;
    return 0;

}
0