結果

問題 No.999 てん vs. ほむ
ユーザー CELICACELICA
提出日時 2020-09-03 22:18:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 2,958 ms
コンパイル使用メモリ 166,908 KB
実行使用メモリ 6,300 KB
最終ジャッジ日時 2023-08-15 19:40:17
合計ジャッジ時間 3,859 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 25 ms
5,840 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 27 ms
6,088 KB
testcase_14 AC 27 ms
6,300 KB
testcase_15 AC 27 ms
6,276 KB
testcase_16 AC 28 ms
6,276 KB
testcase_17 AC 20 ms
6,012 KB
testcase_18 AC 20 ms
6,024 KB
testcase_19 AC 20 ms
5,992 KB
testcase_20 AC 20 ms
5,992 KB
testcase_21 AC 27 ms
6,144 KB
testcase_22 AC 26 ms
6,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;

	vector<ll> a(n * 2);
	ll sumall{ 0 };
	for (auto&& ia : a)
	{
		cin >> ia;
		sumall += ia;
	}

	ll res{ 0 };
	if (n == 1)
		res = abs(a[0] - a[1]);
	else
	{
		vector<ll> suml(n + 1, 0), sumr(n + 1, 0);
		for (int i = 0; i < n; ++i)
		{
			suml[i + 1] = suml[i] + a[i * 2];
			sumr[n - 1 - i] = sumr[n - i] + a[n * 2 - 1 - i * 2];
		}

		for (int i = 0; i < n + 1; ++i)
			res = max(res, (suml[i] + sumr[i]) * 2 - sumall);
	}
	cout << res << "\n";

	return 0;
}
0