結果

問題 No.2601 Very Poor
ユーザー cho435
提出日時 2024-01-12 21:55:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 4,665 ms
コンパイル使用メモリ 250,752 KB
最終ジャッジ日時 2025-02-18 18:11:12
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

int main(){
	int n,x;
	cin>>n>>x;
	vector<int> a(n*2);
	rep(i,n) cin>>a.at(i);
	rep(i,n) a.at(i+n)=a.at(i);
	{
		ll sm=0;
		rep(i,n) sm+=a.at(i);
		if(sm<=x){
			cout<<sm<<"\n";
			return 0;
		}
	}
	vector<ll> sm(n*2+1);
	rep(i,n*2) sm.at(i+1)=sm.at(i)+a.at(i); 
	ll ans=0;
	rep(i,n){
		auto itr=upper_bound(sm.begin(),sm.end(),sm.at(i)+x);
		itr--;
		ans=max(ans,*itr-sm.at(i));
	}
	cout<<ans<<endl;
}
0