結果

問題 No.999 てん vs. ほむ
ユーザー KKT89KKT89
提出日時 2020-02-28 21:31:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 83,220 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-21 17:54:21
合計ジャッジ時間 1,895 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 25 ms
6,272 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 12 ms
5,376 KB
testcase_13 AC 26 ms
6,400 KB
testcase_14 AC 29 ms
6,400 KB
testcase_15 AC 25 ms
6,400 KB
testcase_16 AC 26 ms
6,272 KB
testcase_17 AC 19 ms
6,272 KB
testcase_18 AC 18 ms
6,144 KB
testcase_19 AC 19 ms
6,272 KB
testcase_20 AC 21 ms
6,144 KB
testcase_21 AC 26 ms
6,144 KB
testcase_22 AC 26 ms
6,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(2*n);
	for(int i=0;i<2*n;i++){
		cin >> a[i];
	}
	vector<ll> cnt(n+1,0),cnt2(n+1,0);
	for(int i=0;i<n;i++){
		cnt[i+1]=a[i*2]-a[i*2+1]+cnt[i];
	}
	for(int i=n-1;i>=0;i--){
		cnt2[i]=cnt2[i+1]+a[i*2+1]-a[i*2];
	}
	ll ans=cnt[n];
	for(int i=0;i<n;i++){
		ans=max(ans,cnt[i]+cnt2[i]);
	}
	ans=max(ans,cnt2[0]);
	cout << ans << endl;
}
0