結果

問題 No.3165 [Cherry 7th Tune A] Croissants Continu
ユーザー elphe
提出日時 2025-05-31 11:36:26
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 1,192 ms
コンパイル使用メモリ 101,144 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-05-31 11:36:30
合計ジャッジ時間 3,631 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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, N, i;
	cin >> T;
	vector<uint32_t> A;
	for (i = 0; i != T; ++i)
	{
		cin >> N;
		A.resize(N);
		for (uint32_t j = 0; j != N; ++j)
			cin >> A[j];

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

	return 0;
}
0