結果

問題 No.3165 [Cherry 7th Tune A] Croissants Continu
ユーザー elphe
提出日時 2025-05-31 11:52:30
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 1,219 ms
コンパイル使用メモリ 101,304 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-31 11:52:34
合計ジャッジ時間 3,432 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

static inline constexpr uint64_t solve(const uint32_t N, const vector<uint32_t>& A) noexcept
{
	const uint32_t max_A = *max_element(A.begin(), A.end());
	const uint64_t sum_A = accumulate(A.begin(), A.end(), UINT64_C(0));

	if ((max_A << 1) <= sum_A)
		return sum_A;
	else
		return ((sum_A - max_A) << 1) + 1;
}

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	uint32_t T, i;
	cin >> T;
	for (i = 0; i != T; ++i)
	{
		uint32_t N, j;
		cin >> N;
		vector<uint32_t> A(N);
		for (j = 0; j != N; ++j)
			cin >> A[j];

		cout << solve(N, A) << '\n';
	}

	return 0;
}
0