結果

問題 No.999 てん vs. ほむ
ユーザー hirokazu1020hirokazu1020
提出日時 2020-02-28 21:30:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 986 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 94,436 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-21 17:53:13
合計ジャッジ時間 1,995 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 24 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 25 ms
5,760 KB
testcase_14 AC 25 ms
5,760 KB
testcase_15 AC 25 ms
5,760 KB
testcase_16 AC 24 ms
5,760 KB
testcase_17 AC 17 ms
5,504 KB
testcase_18 AC 17 ms
5,376 KB
testcase_19 AC 17 ms
5,376 KB
testcase_20 AC 17 ms
5,376 KB
testcase_21 AC 23 ms
5,632 KB
testcase_22 AC 24 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
int a[200000];
long long b[200001];

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

	cin >> n;
	rep(i, n*2)cin >> a[i];

	b[2*n] = 0;
	for (int i = 2*n - 2; i >= 0; i -= 2) {
		b[i] = b[i + 2] + a[i + 1] - a[i];
	}
	long long ans = b[0], s = 0;
	for (int i = 0; i < 2 * n; i += 2) {
		s += a[i] - a[i + 1];
		ans = max(ans, s + b[i + 2]);
	}
	cout << ans << endl;


	return 0;
}
0