結果

問題 No.999 てん vs. ほむ
ユーザー sprng_wlsprng_wl
提出日時 2020-02-28 21:31:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 170,464 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-10-13 16:50:00
合計ジャッジ時間 3,315 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<Int> a(2 * N);
	for (int i = 0; i < 2 * N; ++i) { cin >> a[i]; }

	vector<Int> dL(2 * N, 0), dR(2 * N, 0);
	for (int i = 0; i < 2 * N; ++i) {
		dL[i] += (i % 2 ? -a[i] : a[i]);
		if (i > 0) { dL[i] += dL[i - 1]; }
	}
	for (int i = 2 * N - 1; i >= 0; --i) {
		dR[i] += (i % 2 ? a[i] : -a[i]);
		if (i + 1 < 2 * N) { dR[i] += dR[i + 1]; }
	}

	Int ans = max(dR[0], dL.back());
	for (int i = 1; i + 1 < 2 * N; i += 2) {
		ans = max(ans, dL[i] + dR[i + 1]);
	}
	cout << ans << endl;

	return 0;
}
0