結果

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;


#include<atcoder/modint>
using mint = atcoder::modint998244353;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll ans = 0;
    ll n,x;
    cin>>n>>x;
    vector<ll> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    vector<ll> sum(n+1,0);
    for(int i =0 ;i<n;i++){
        sum[i+1] = sum[i] + a[i];
    }
    for(int i = 0;i<n;i++){
        if(a[i]>x) continue;
        int right = n;
        int left = 0;
        while(right-left>1){
            int mid = (right+left) / 2;
            ll use = 0;
            if(i+mid<=n){
                use = sum[i+mid] - sum[i];
            }else{
                use = sum[n] - sum[i];
                int res = mid - (n-i);
                use += sum[res];
            }
            if(use<=x) ans = max(ans,use);
            if(use<=x) left = mid;
            else right = mid;
        }
    }
    if(sum[n]<=x) ans = sum[n];
    cout<<ans<<endl;
}

0