結果

問題 No.3165 [Cherry 7th Tune A] Croissants Continu
ユーザー elphe
提出日時 2025-05-31 11:34:28
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 1,183 ms
コンパイル使用メモリ 103,192 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2025-05-31 11:34:33
合計ジャッジ時間 3,917 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, i;
	cin >> T;
	vector<uint32_t> N(T);
	vector<vector<uint32_t>> A(T);
	for (i = 0; i != T; ++i)
	{
		cin >> N[i];
		A[i].resize(N[i]);
		for (uint32_t j = 0; j != N[i]; ++j)
			cin >> A[i][j];
	}

	for (i = 0; i != T; ++i)
		cout << solve(N[i], A[i]) << '\n';

	return 0;
}
0