結果

問題 No.999 てん vs. ほむ
ユーザー furafura
提出日時 2020-05-05 19:22:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 512 bytes
コンパイル時間 1,932 ms
コンパイル使用メモリ 201,360 KB
実行使用メモリ 7,024 KB
最終ジャッジ日時 2023-09-09 08:07:19
合計ジャッジ時間 4,465 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 28 ms
6,460 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 13 ms
4,588 KB
testcase_13 AC 31 ms
6,968 KB
testcase_14 AC 31 ms
7,024 KB
testcase_15 AC 30 ms
7,024 KB
testcase_16 AC 31 ms
7,020 KB
testcase_17 AC 23 ms
6,704 KB
testcase_18 AC 23 ms
6,552 KB
testcase_19 AC 24 ms
6,760 KB
testcase_20 AC 23 ms
6,724 KB
testcase_21 AC 30 ms
7,020 KB
testcase_22 AC 29 ms
6,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(2*n);
	rep(i,2*n) scanf("%d",&a[i]);

	lint total=accumulate(a.begin(),a.end(),0LL);

	vector<lint> lsum(2*n+1),rsum(2*n+1);
	rep(i,2*n){
		lsum[i+1]=lsum[i]+(i%2==0?a[i]:0);
	}
	for(int i=2*n;i>0;i--){
		rsum[i-1]=rsum[i]+(i%2==0?a[i-1]:0);
	}

	lint res=0;
	rep(i,n+1) res=max(res,lsum[2*i]+rsum[2*i]);
	printf("%lld\n",2*res-total);

	return 0;
}
0