結果

問題 No.2601 Very Poor
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2024-01-12 21:40:37
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 600 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 205,916 KB
実行使用メモリ 9,592 KB
最終ジャッジ日時 2024-09-30 06:19:04
合計ジャッジ時間 4,277 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
	int N;
	ll X;
	cin >> N >> X;
	std::vector<ll> A(N);
	for (auto& a : A) cin >> a;
	if (accumulate(A.begin(), A.end(), 0ll) <= X) {
		cout << accumulate(A.begin(), A.end(), 0ll) << endl;
		return 0;
	}
	for (int i = 0; i < N; i ++) A.push_back(A[i]);
	vector<ll> sum(N * 2 + 1, 0);
	for (int i = 1; i <= N; i ++) sum[i] = sum[i - 1] + A[i - 1];
	ll ans = 0;
	int r = 0;
	for (int l = 0; l < N; l ++) {
		while (r <= N * 2 && sum[r] - sum[l] <= X) r ++;
		ans = max(ans, sum[r - 1] - sum[l]);
	}
	cout << ans << endl;
}
0