結果

問題 No.999 てん vs. ほむ
ユーザー CELICA
提出日時 2020-09-03 22:18:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 168,784 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-11-24 04:09:15
合計ジャッジ時間 3,340 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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