結果

問題 No.999 てん vs. ほむ
ユーザー KKT89
提出日時 2020-02-28 21:31:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 79,592 KB
最終ジャッジ日時 2025-01-09 02:35:57
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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